Skip to content

Commit cd29e6d

Browse files
committed
disable renounceOwnership
1 parent 7dcbd2f commit cd29e6d

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

src/autoRecovery/Allowlist.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ contract Allowlist is Ownable {
1414
error NotAllowed(address addr);
1515
/// @notice The provided index hint does not point at the expected address.
1616
error IndexMismatch(uint256 index, address expected, address actual);
17+
/// @notice Ownership renunciation is disabled to keep allowlist administration available.
18+
error OwnershipRenunciationDisabled();
1719

1820
mapping(address => bool) private _allowed;
1921
address[] private _entries;
@@ -74,6 +76,11 @@ contract Allowlist is Ownable {
7476
return _entries;
7577
}
7678

79+
/// @notice Disables ownership renunciation to avoid permanently locked administration.
80+
function renounceOwnership() public view override onlyOwner {
81+
revert OwnershipRenunciationDisabled();
82+
}
83+
7784
function _add(address addr, bool emitEvent) private {
7885
if (addr == address(0)) revert ZeroAddress();
7986
if (_allowed[addr]) revert AlreadyAllowed(addr);

src/pausable/Pausable.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ abstract contract Pausable is Ownable {
1414
error EnforcedPause();
1515
/// @notice The contract is not paused.
1616
error ExpectedPause();
17+
/// @notice Ownership renunciation is disabled to keep pause recovery available.
18+
error OwnershipRenunciationDisabled();
1719

1820
/// @notice Returns whether `account` is allowed to pause.
1921
mapping(address => bool) public isOperator;
@@ -77,6 +79,11 @@ abstract contract Pausable is Ownable {
7779
_setOperator(operator, allowed);
7880
}
7981

82+
/// @notice Disables ownership renunciation to avoid permanently locked pause state.
83+
function renounceOwnership() public view override onlyOwner {
84+
revert OwnershipRenunciationDisabled();
85+
}
86+
8087
function _setOperator(address operator, bool allowed) private {
8188
if (operator == address(0)) {
8289
revert ZeroAddress();

test/Allowlist.t.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,29 @@ contract AllowlistTest is Test {
405405
assertEq(allowlist.getAllowed().length, 0);
406406
}
407407

408+
function testFuzz_renounceOwnership_revertsAndKeepsOwner(address owner_) external {
409+
vm.assume(owner_ != address(0));
410+
411+
Allowlist allowlist = _newAllowlist(owner_);
412+
413+
vm.prank(owner_);
414+
vm.expectRevert(Allowlist.OwnershipRenunciationDisabled.selector);
415+
allowlist.renounceOwnership();
416+
417+
assertEq(allowlist.owner(), owner_);
418+
}
419+
420+
function testFuzz_renounceOwnership_revertsForNonOwner(address owner_, address caller) external {
421+
vm.assume(owner_ != address(0));
422+
vm.assume(caller != owner_);
423+
424+
Allowlist allowlist = _newAllowlist(owner_);
425+
426+
vm.prank(caller);
427+
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, caller));
428+
allowlist.renounceOwnership();
429+
}
430+
408431
function testFuzz_addRemoveAdd(address owner_, address addr) external {
409432
vm.assume(owner_ != address(0));
410433
vm.assume(addr != address(0));

test/Pausable.t.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@ contract PausableTest is Test {
194194
pausable.setOperator(address(0), true);
195195
}
196196

197+
function test_renounceOwnership_revertsAndKeepsOwner() external {
198+
PausableHarness pausable = _newPausable();
199+
200+
vm.prank(owner_);
201+
vm.expectRevert(Pausable.OwnershipRenunciationDisabled.selector);
202+
pausable.renounceOwnership();
203+
204+
assertEq(pausable.owner(), owner_);
205+
}
206+
207+
function test_renounceOwnership_revertsForNonOwner() external {
208+
PausableHarness pausable = _newPausable();
209+
210+
vm.prank(outsider);
211+
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, outsider));
212+
pausable.renounceOwnership();
213+
}
214+
197215
function test_whenNotPausedModifier() external {
198216
PausableHarness pausable = _newPausable();
199217

0 commit comments

Comments
 (0)