Skip to content

Commit

Permalink
fix: only admin can close, fix mint to zero addr receiver, and format…
Browse files Browse the repository at this point in the history
…ting default admin string error
  • Loading branch information
marcomariscal committed Dec 12, 2024
1 parent 7da3772 commit 57e1f4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions l2-contracts/src/ZkCappedMinterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ contract ZkCappedMinterV2 is AccessControl, Pausable {

/// @notice Permanently closes the contract, preventing any future minting.
/// @dev Once closed, the contract cannot be reopened and all minting operations will be permanently blocked.
/// @dev Only callable by accounts with the PAUSER_ROLE.
/// @dev Only callable by the admin.
function close() external {
_checkRole(PAUSER_ROLE, msg.sender);
_checkRole(DEFAULT_ADMIN_ROLE, msg.sender);
closed = true;
_pause();
}
Expand Down
15 changes: 8 additions & 7 deletions l2-contracts/test/ZkCappedMinterV2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract ZkCappedMinterV2Test is ZkTokenTest {
"AccessControl: account ",
Strings.toHexString(uint160(account), 20),
" is missing role ",
Strings.toHexString(uint256(role))
Strings.toHexString(uint256(role), 32)
)
);
}
Expand All @@ -60,6 +60,7 @@ contract Mint is ZkCappedMinterV2Test {
address _receiver,
uint256 _amount
) public {
vm.assume(_receiver != address(0));
_amount = bound(_amount, 1, DEFAULT_CAP);

_grantMinterRole(cappedMinter, cappedMinterAdmin, _minter);
Expand Down Expand Up @@ -220,7 +221,7 @@ contract Close is ZkCappedMinterV2Test {
_amount = bound(_amount, 1, _cap);
vm.assume(_receiver != address(0) && _receiver != initMintReceiver);

ZkCappedMinterV2 cappedMinter = createCappedMinter(_cappedMinterAdmin, _cap);
ZkCappedMinterV2 cappedMinter = _createCappedMinter(_cappedMinterAdmin, _cap);
vm.prank(_cappedMinterAdmin);
cappedMinter.grantRole(MINTER_ROLE, _minter);

Expand All @@ -237,13 +238,13 @@ contract Close is ZkCappedMinterV2Test {
cappedMinter.unpause();
}

function testFuzz_RevertIf_NotPauserRoleCloses(address _cappedMinterAdmin, address _nonPauser, uint256 _cap) public {
vm.assume(_nonPauser != _cappedMinterAdmin);
function testFuzz_RevertIf_NotAdminCloses(address _cappedMinterAdmin, address _nonAdmin, uint256 _cap) public {
vm.assume(_nonAdmin != _cappedMinterAdmin);
_cap = bound(_cap, 0, MAX_MINT_SUPPLY);

ZkCappedMinterV2 cappedMinter = createCappedMinter(_cappedMinterAdmin, _cap);
vm.expectRevert(_formatAccessControlError(_nonPauser, PAUSER_ROLE));
vm.prank(_nonPauser);
ZkCappedMinterV2 cappedMinter = _createCappedMinter(_cappedMinterAdmin, _cap);
vm.expectRevert(_formatAccessControlError(_nonAdmin, DEFAULT_ADMIN_ROLE));
vm.prank(_nonAdmin);
cappedMinter.close();
}
}

0 comments on commit 57e1f4f

Please sign in to comment.