Skip to content

Commit

Permalink
fix: [audit] ZNS-12 Missing input validation (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Whytecrowe authored Oct 31, 2023
2 parents 4824679 + 8390856 commit e2c258b
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 336 deletions.
4 changes: 4 additions & 0 deletions contracts/access/ZNSAccessController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ contract ZNSAccessController is AccessControl, ZNSRoles, IZNSAccessController {
function _grantRoleToMany(bytes32 role, address[] memory addresses) internal {
uint256 length = addresses.length;
for (uint256 i = 0; i < length; ++i) {
require(
addresses[i] != address(0),
"ZNSAccessController: Can't grant role to zero address"
);
_grantRole(role, addresses[i]);
}
}
Expand Down
673 changes: 339 additions & 334 deletions contracts/price/ZNSCurvePricer.sol

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions contracts/price/ZNSFixedPricer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ contract ZNSFixedPricer is AAccessControlled, ARegistryWired, UUPSUpgradeable, I
* @param feePercentage The new feePercentage
*/
function _setFeePercentage(bytes32 domainHash, uint256 feePercentage) internal {
require(
feePercentage <= PERCENTAGE_BASIS,
"ZNSFixedPricer: feePercentage cannot be greater than PERCENTAGE_BASIS"
);

priceConfigs[domainHash].feePercentage = feePercentage;
emit FeePercentageSet(domainHash, feePercentage);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/ZNSRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract ZNSRegistry is AAccessControlled, UUPSUpgradeable, IZNSRegistry {
/**
* @notice Initializer for the `ZNSRegistry` proxy.
* @param accessController_ The address of the `ZNSAccessController` contract
* @dev ! The owner of the 0x0 hash should be a multisig !
* @dev ! The owner of the 0x0 hash should be a multisig ideally, but EOA can be used to deploy !
* > Admin account deploying the contract will be the owner of the 0x0 hash !
*/
function initialize(address accessController_) external override initializer {
Expand Down
11 changes: 11 additions & 0 deletions test/ZNSAccessController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { deployAccessController } from "./helpers";
import { expect } from "chai";
import { ADMIN_ROLE, GOVERNOR_ROLE, EXECUTOR_ROLE, REGISTRAR_ROLE } from "./helpers/access";
import { getAccessRevertMsg } from "./helpers/errors";
import { ethers } from "hardhat";


describe("ZNSAccessController", () => {
Expand Down Expand Up @@ -46,6 +47,16 @@ describe("ZNSAccessController", () => {
}, Promise.resolve()
);
});

it("Should revert when passing 0x0 address to assing roles", async () => {
await expect(
deployAccessController({
deployer,
governorAddresses: [ ethers.constants.AddressZero ],
adminAddresses: [ ethers.constants.AddressZero ],
})
).to.be.revertedWith("ZNSAccessController: Can't grant role to zero address");
});
});

describe("Role Management from the Initial Setup", () => {
Expand Down
9 changes: 8 additions & 1 deletion test/ZNSCurvePricer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ describe("ZNSCurvePricer", () => {
});
});

describe("#setRegistrationFeePercentage", () => {
describe("#setFeePercentage", () => {
it("Successfully sets the fee percentage", async () => {
const newFeePerc = BigNumber.from(222);
await zns.curvePricer.connect(user).setFeePercentage(domainHash, newFeePerc);
Expand All @@ -863,6 +863,13 @@ describe("ZNSCurvePricer", () => {
.setFeePercentage(domainHash, newFeePerc);
await expect(tx).to.be.revertedWith(NOT_AUTHORIZED_REG_WIRED_ERR);
});

it("should revert when trying to set feePercentage higher than PERCENTAGE_BASIS", async () => {
const newFeePerc = BigNumber.from(10001);
await expect(
zns.curvePricer.connect(user).setFeePercentage(domainHash, newFeePerc)
).to.be.revertedWith("ZNSCurvePricer: feePercentage cannot be greater than PERCENTAGE_BASIS");
});
});

describe("#getRegistrationFee", () => {
Expand Down
8 changes: 8 additions & 0 deletions test/ZNSFixedPricer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ describe("ZNSFixedPricer", () => {
);
});

it("#setFeePercentage() should revert when trying to set feePercentage higher than PERCENTAGE_BASIS", async () => {
await expect(
zns.fixedPricer.connect(user).setFeePercentage(domainHash, PERCENTAGE_BASIS.add(1))
).to.be.revertedWith(
"ZNSFixedPricer: feePercentage cannot be greater than PERCENTAGE_BASIS"
);
});

// eslint-disable-next-line max-len
it("#setPriceConfig() should set the price config correctly and emit #PriceSet and #FeePercentageSet events", async () => {
const newPrice = ethers.utils.parseEther("1823");
Expand Down

0 comments on commit e2c258b

Please sign in to comment.