Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [audit] ZNS-4: Address price drop going lower than minPrice before maxLength #62

Merged
merged 6 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions contracts/price/ZNSCurvePricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
if (length <= config.baseLength) return config.maxPrice;
if (length > config.maxLength) return config.minPrice;

return
(config.baseLength * config.maxPrice / length)
return (config.baseLength * config.maxPrice / length)
/ config.precisionMultiplier * config.precisionMultiplier;
}

Expand All @@ -304,7 +303,7 @@ contract ZNSCurvePricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
* which can occur if some of the config values are not properly chosen and set.
*/
function _validateConfig(bytes32 domainHash) internal view {
uint256 prevToMinPrice = _getPrice(domainHash, priceConfigs[domainHash].maxLength - 1);
uint256 prevToMinPrice = _getPrice(domainHash, priceConfigs[domainHash].maxLength);
require(
priceConfigs[domainHash].minPrice <= prevToMinPrice,
"ZNSCurvePricer: incorrect value set causes the price spike at maxLength."
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const config : HardhatUserConfig = {
timeout: 5000000,
},
gasReporter: {
enabled: true
enabled: false
},
networks: {
mainnet: {
Expand Down
16 changes: 16 additions & 0 deletions test/ZNSCurvePricer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ describe("ZNSCurvePricer", () => {
).to.be.revertedWith(CURVE_PRICE_CONFIG_ERR);
});

it("Cannot go below the set minPrice", async () => {
// Using config numbers from audit
const newConfig = {
baseLength: BigNumber.from("5"),
maxLength: BigNumber.from("10"),
maxPrice: parseEther("10"),
minPrice: parseEther("5.5"),
precisionMultiplier: precisionMultiDefault,
feePercentage: registrationFeePercDefault,
};

await expect(
zns.curvePricer.connect(user).setPriceConfig(domainHash, newConfig)
).to.be.revertedWith(CURVE_PRICE_CONFIG_ERR);
});

it("Should revert if called by anyone other than owner or operator", async () => {
const newConfig = {
baseLength: BigNumber.from("6"),
Expand Down
2 changes: 1 addition & 1 deletion test/ZNSSubRegistrar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ describe("ZNSSubRegistrar", () => {

it("CurvePricer - StakePayment - stake fee - 13 decimals", async () => {
const priceConfig = {
maxPrice: parseUnits("25000.93", decimalValues.thirteen),
maxPrice: parseUnits("30000.93", decimalValues.thirteen),
minPrice: parseUnits("2000.11", decimalValues.thirteen),
maxLength: BigNumber.from(50),
baseLength: BigNumber.from(4),
Expand Down