Skip to content

Commit

Permalink
feat(contracts): allow owner to disable allowlist
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhalliday committed Mar 4, 2024
1 parent 76ad9d7 commit 5c4baad
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 31 deletions.
66 changes: 37 additions & 29 deletions contracts/.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,48 @@ FeeOracleV1_Test:test_feeFor_succeeds() (gas: 38619)
FeeOracleV1_Test:test_setFee_nonOwner_reverts() (gas: 20220)
FeeOracleV1_Test:test_setFee_succeeds() (gas: 30824)
FeeOracleV1_Test:test_setFee_zero_reverts() (gas: 20212)
OmniAVS_admin_Test:test_avsDirectory_succeeds() (gas: 14958)
OmniAVS_admin_Test:test_deregisterOperator_byOwner_succeeds() (gas: 334463)
OmniAVS_admin_Test:test_deregisterOperator_whenPaused_reverts() (gas: 69739)
OmniAVS_admin_Test:test_getOPeratorRestakedStrategies_notOperator_succeeds() (gas: 42527)
OmniAVS_admin_Test:test_getOperatorRestakedStrategies_noStrategies_succeeds() (gas: 308750)
OmniAVS_admin_Test:test_getOperatorRestakedStrategies_succeeds() (gas: 369440)
OmniAVS_admin_Test:test_avsDirectory_succeeds() (gas: 14936)
OmniAVS_admin_Test:test_deregisterOperator_byOwner_succeeds() (gas: 336544)
OmniAVS_admin_Test:test_deregisterOperator_whenPaused_reverts() (gas: 69695)
OmniAVS_admin_Test:test_getOPeratorRestakedStrategies_notOperator_succeeds() (gas: 42505)
OmniAVS_admin_Test:test_getOperatorRestakedStrategies_noStrategies_succeeds() (gas: 310943)
OmniAVS_admin_Test:test_getOperatorRestakedStrategies_succeeds() (gas: 371633)
OmniAVS_admin_Test:test_getRestakeableStrategies_noStrategies_succeeds() (gas: 26202)
OmniAVS_admin_Test:test_getRestakeableStrategies_succeeds() (gas: 84470)
OmniAVS_admin_Test:test_pause_byOwner_succeeds() (gas: 44820)
OmniAVS_admin_Test:test_registerOperator_whenPaused_reverts() (gas: 70928)
OmniAVS_admin_Test:test_setEthStakeInbox_notOwner_reverts() (gas: 17955)
OmniAVS_admin_Test:test_setEthStakeInbox_succeeds() (gas: 26693)
OmniAVS_admin_Test:test_setMetadataURI_notOwner_reverts() (gas: 18722)
OmniAVS_admin_Test:test_setMetadataURI_succeeds() (gas: 38560)
OmniAVS_admin_Test:test_setOmniChainId_notOwner_reverts() (gas: 17973)
OmniAVS_admin_Test:test_setOmniChainId_succeeds() (gas: 26660)
OmniAVS_admin_Test:test_pause_byOwner_succeeds() (gas: 44776)
OmniAVS_admin_Test:test_registerOperator_whenPaused_reverts() (gas: 70973)
OmniAVS_admin_Test:test_setEthStakeInbox_notOwner_reverts() (gas: 17977)
OmniAVS_admin_Test:test_setEthStakeInbox_succeeds() (gas: 26780)
OmniAVS_admin_Test:test_setMetadataURI_notOwner_reverts() (gas: 18700)
OmniAVS_admin_Test:test_setMetadataURI_succeeds() (gas: 38538)
OmniAVS_admin_Test:test_setOmniChainId_notOwner_reverts() (gas: 17951)
OmniAVS_admin_Test:test_setOmniChainId_succeeds() (gas: 26638)
OmniAVS_admin_Test:test_setPortal_notOwner_reverts() (gas: 17912)
OmniAVS_admin_Test:test_setPortal_succeeds() (gas: 26695)
OmniAVS_admin_Test:test_setStrategyParams_duplicateStrategy_reverts() (gas: 37824)
OmniAVS_admin_Test:test_setStrategyParams_notOwner_reverts() (gas: 18350)
OmniAVS_admin_Test:test_setPortal_succeeds() (gas: 26673)
OmniAVS_admin_Test:test_setStrategyParams_duplicateStrategy_reverts() (gas: 37802)
OmniAVS_admin_Test:test_setStrategyParams_notOwner_reverts() (gas: 18328)
OmniAVS_admin_Test:test_setStrategyParams_succeds() (gas: 70124)
OmniAVS_admin_Test:test_setStrategyParams_twice_succeeds() (gas: 48781)
OmniAVS_admin_Test:test_setStrategyParams_zeroAddress_reverts() (gas: 36835)
OmniAVS_admin_Test:test_setXCallGasLimits_notOwner_reverts() (gas: 18056)
OmniAVS_admin_Test:test_setXCallGasLimits_succeeds() (gas: 31912)
OmniAVS_admin_Test:test_syncWithOmni_whenPaused_reverts() (gas: 45232)
OmniAVS_admin_Test:test_setStrategyParams_twice_succeeds() (gas: 48759)
OmniAVS_admin_Test:test_setStrategyParams_zeroAddress_reverts() (gas: 36813)
OmniAVS_admin_Test:test_setXCallGasLimits_notOwner_reverts() (gas: 18078)
OmniAVS_admin_Test:test_setXCallGasLimits_succeeds() (gas: 32024)
OmniAVS_admin_Test:test_syncWithOmni_whenPaused_reverts() (gas: 45210)
OmniAVS_admin_Test:test_unpause_byOwner_succeeds() (gas: 35650)
OmniAVS_allowlist_Test:test_addToAllowlist_notOwner_reverts() (gas: 42417)
OmniAVS_allowlist_Test:test_addToAllowlist_succeeds() (gas: 69742)
OmniAVS_allowlist_Test:test_registerOperator_succeeds() (gas: 664896)
OmniAVS_allowlist_Test:test_removeFromAllowlist_notOwner_reverts() (gas: 42342)
OmniAVS_allowlist_Test:test_removeFromAllowlist_succeeds() (gas: 109355)
OmniAVS_initialize_Test:test_initialize_defaultParams_succeeds() (gas: 2789031)
OmniAVS_syncWithOmni_Test:test_depositBeaconEth_succeeds() (gas: 475197)
OmniAVS_allowlist_Test:test_addToAllowlist_notOwner_reverts() (gas: 42465)
OmniAVS_allowlist_Test:test_addToAllowlist_succeeds() (gas: 69786)
OmniAVS_allowlist_Test:test_disableAllowlist_alreadyDisabled_reverts() (gas: 30030)
OmniAVS_allowlist_Test:test_disableAllowlist_notOwner_reverts() (gas: 17756)
OmniAVS_allowlist_Test:test_disableAllowlist_succeeds() (gas: 27337)
OmniAVS_allowlist_Test:test_enableAllowlist_alreadyEnabled_reverts() (gas: 24044)
OmniAVS_allowlist_Test:test_enableAllowlist_notOwner_reverts() (gas: 17756)
OmniAVS_allowlist_Test:test_enableAllowlist_succeeds() (gas: 27699)
OmniAVS_allowlist_Test:test_registerOperator_allowlistDisabled_succeeds() (gas: 312121)
OmniAVS_allowlist_Test:test_registerOperator_nowAllowed_reverts() (gas: 48322)
OmniAVS_allowlist_Test:test_registerOperator_succeeds() (gas: 667176)
OmniAVS_allowlist_Test:test_removeFromAllowlist_notOwner_reverts() (gas: 42413)
OmniAVS_allowlist_Test:test_removeFromAllowlist_succeeds() (gas: 109390)
OmniAVS_initialize_Test:test_initialize_defaultParams_succeeds() (gas: 2879122)
OmniAVS_syncWithOmni_Test:test_depositBeaconEth_succeeds() (gas: 475412)
OmniPortal_admin_Test:test_setFeeOracle_nonOwner_reverts() (gas: 20322)
OmniPortal_admin_Test:test_setFeeOracle_succeeds() (gas: 31835)
OmniPortal_admin_Test:test_setFeeOracle_zero_reverts() (gas: 20375)
Expand Down
20 changes: 20 additions & 0 deletions contracts/src/interfaces/IOmniAVSAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ interface IOmniAVSAdmin {
*/
event OperatorDisallowed(address operator);

/**
* @notice Emitted when the allowlist is enabled.
*/
event AllowlistEnabled();

/**
* @notice Emitted when the allowlist is disabled.
*/
event AllowlistDisabled();

/**
* @notice Initialize the Omni AVS admin contract.
* @param owner Intiial contract owner
Expand Down Expand Up @@ -86,6 +96,16 @@ interface IOmniAVSAdmin {
*/
function removeFromAllowlist(address operator) external;

/**
* @notice Enable the allowlist.
*/
function enableAllowlist() external;

/**
* @notice Disable the allowlist.
*/
function disableAllowlist() external;

/**
* @notice Pause the contract.
*/
Expand Down
21 changes: 20 additions & 1 deletion contracts/src/protocol/OmniAVS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ contract OmniAVS is
omniChainId = omniChainId_;
xcallGasLimitPerOperator = 50_000;
xcallBaseGasLimit = 75_000;
allowlistEnabled = true;
ethStakeInbox = ethStakeInbox_;

_transferOwnership(owner_);
Expand All @@ -86,7 +87,7 @@ contract OmniAVS is
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature
) external whenNotPaused {
require(msg.sender == operator, "OmniAVS: only operator");
require(_allowlist[operator], "OmniAVS: not allowed");
require(!allowlistEnabled || _allowlist[operator], "OmniAVS: not allowed");
require(!_isOperator(operator), "OmniAVS: already an operator"); // we could let _avsDirectory.regsiterOperatorToAVS handle this, they do check

_addOperator(operator);
Expand Down Expand Up @@ -275,6 +276,24 @@ contract OmniAVS is
emit OperatorDisallowed(operator);
}

/**
* @notice Enable the allowlist.
*/
function enableAllowlist() external onlyOwner {
require(!allowlistEnabled, "OmniAVS: already enabled");
allowlistEnabled = true;
emit AllowlistEnabled();
}

/**
* @notice Disable the allowlist.
*/
function disableAllowlist() external onlyOwner {
require(allowlistEnabled, "OmniAVS: already disabled");
allowlistEnabled = false;
emit AllowlistDisabled();
}

/**
* @notice Pause the contract.
* @dev This pauses registerOperatorToAVS, deregisterOperatorFromAVS, and syncWithOmni.
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/protocol/OmniAVSStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ abstract contract OmniAVSStorage {
/// @notice OmniPortal.xcall base gas limit in syncWithOmni()
uint64 public xcallBaseGasLimit;

/// @notice Whether or not the allowlist is enabled
bool public allowlistEnabled;

/// @notice Address of EthStakeInbox contract, predeployed on Omni
address public ethStakeInbox;

Expand Down
70 changes: 69 additions & 1 deletion contracts/test/avs/OmniAVS_allowlist.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract OmniAVS_allowlist_Test is Base {
omniAVS.removeFromAllowlist(operator);
}

/// @dev Test that an operator can register if in allow list
/// @dev Test that an operator can register if in allowlist
function test_registerOperator_succeeds() public {
address operator = _operator(0);

Expand All @@ -62,4 +62,72 @@ contract OmniAVS_allowlist_Test is Base {
assertEq(operators.length, 1);
assertEq(operators[0].addr, operator);
}

/// @dev Test that an operator can't register if not in allowlist
function test_registerOperator_nowAllowed_reverts() public {
address operator = _operator(0);
ISignatureUtils.SignatureWithSaltAndExpiry memory emptySig;

vm.expectRevert("OmniAVS: not allowed");
vm.prank(operator);
omniAVS.registerOperatorToAVS(operator, emptySig);
}

/// @dev Test that the owner can disable the allowlist
function test_disableAllowlist_succeeds() public {
vm.prank(omniAVSOwner);
omniAVS.disableAllowlist();
assertFalse(omniAVS.allowlistEnabled());
}

/// @dev Test that only the owner can disable the allowlist
function test_disableAllowlist_notOwner_reverts() public {
vm.expectRevert("Ownable: caller is not the owner");
omniAVS.disableAllowlist();
}

/// @dev Test that the allowlist can't be disabled if already disabled
function test_disableAllowlist_alreadyDisabled_reverts() public {
_disableAllowlist();
assertFalse(omniAVS.allowlistEnabled());
vm.expectRevert("OmniAVS: already disabled");
vm.prank(omniAVSOwner);
omniAVS.disableAllowlist();
}

/// @dev Test that the owner can enable the allowlist
function test_enableAllowlist_succeeds() public {
_disableAllowlist();
vm.prank(omniAVSOwner);
omniAVS.enableAllowlist();
assertTrue(omniAVS.allowlistEnabled());
}

/// @dev Test that only the owner can enable the allowlist
function test_enableAllowlist_notOwner_reverts() public {
vm.expectRevert("Ownable: caller is not the owner");
omniAVS.enableAllowlist();
}

/// @dev Test that the allowlist can't be enabled if already enabled
function test_enableAllowlist_alreadyEnabled_reverts() public {
assertTrue(omniAVS.allowlistEnabled());
vm.expectRevert("OmniAVS: already enabled");
vm.prank(omniAVSOwner);
omniAVS.enableAllowlist();
}

/// @dev Test that an operator can register if not in allowlist, if allowlist is disabled
function test_registerOperator_allowlistDisabled_succeeds() public {
address operator = _operator(0);

_disableAllowlist();
_registerAsOperator(operator);
_registerOperatorWithAVS(operator);

IOmniAVS.Operator[] memory operators = omniAVS.operators();

assertEq(operators.length, 1);
assertEq(operators[0].addr, operator);
}
}
12 changes: 12 additions & 0 deletions contracts/test/avs/common/Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ contract Utils is Fixtures {
omniAVS.removeFromAllowlist(operator);
}

/// @dev disable the allowlist
function _disableAllowlist() internal {
vm.prank(omniAVSOwner);
omniAVS.disableAllowlist();
}

/// @dev enable the allowlist
function _enableAllowlist() internal {
vm.prank(omniAVSOwner);
omniAVS.enableAllowlist();
}

/// @dev deregister an operator from OmniAVS
function _deregisterOperatorFromAVS(address operator) internal {
vm.prank(operator);
Expand Down

0 comments on commit 5c4baad

Please sign in to comment.