Skip to content

Commit

Permalink
refactor: whitelister addr (#110)
Browse files Browse the repository at this point in the history
* refactor: wihtelister addr

* fix: set whitelister during init

* Update contracts/src/core/MachServiceManager.sol

Co-authored-by: Noel <[email protected]>

* fix: rename error

---------

Co-authored-by: Noel <[email protected]>
  • Loading branch information
renlulu and neutiyoo authored Apr 8, 2024
1 parent 6d02245 commit e0531e5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
31 changes: 28 additions & 3 deletions contracts/src/core/MachServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {ServiceManagerBase} from "eigenlayer-middleware/ServiceManagerBase.sol";
import {MachServiceManagerStorage} from "./MachServiceManagerStorage.sol";
import {
InvalidConfirmer,
NotWhitelister,
ZeroAddress,
AlreadyInAllowlist,
NotInAllowlist,
Expand Down Expand Up @@ -63,6 +64,14 @@ contract MachServiceManager is
_;
}

/// @notice when applied to a function, ensures that the function is only callable by the `whitelister`.
modifier onlyWhitelister() {
if (_msgSender() != whitelister) {
revert NotWhitelister();
}
_;
}

constructor(
IAVSDirectory __avsDirectory,
IRegistryCoordinator __registryCoordinator,
Expand All @@ -80,11 +89,13 @@ contract MachServiceManager is
IPauserRegistry _pauserRegistry,
uint256 _initialPausedStatus,
address _initialOwner,
address _alertConfirmer
address _alertConfirmer,
address _whitelister
) public initializer {
_initializePauser(_pauserRegistry, _initialPausedStatus);
__ServiceManagerBase_init(_initialOwner);
_setAlertConfirmer(_alertConfirmer);
_setWhitelister(_whitelister);
allowlistEnabled = true;
quorumThresholdPercentage = 66;
}
Expand All @@ -97,7 +108,7 @@ contract MachServiceManager is
* @notice Add an operator to the allowlist.
* @param operator The operator to add
*/
function addToAllowlist(address operator) external onlyOwner {
function addToAllowlist(address operator) external onlyWhitelister {
if (operator == address(0)) {
revert ZeroAddress();
}
Expand All @@ -112,7 +123,7 @@ contract MachServiceManager is
* @notice Remove an operator from the allowlist.
* @param operator The operator to remove
*/
function removeFromAllowlist(address operator) external onlyOwner {
function removeFromAllowlist(address operator) external onlyWhitelister {
if (!allowlist[operator]) {
revert NotInAllowlist();
}
Expand Down Expand Up @@ -151,6 +162,13 @@ contract MachServiceManager is
_setAlertConfirmer(confirmer);
}

/**
* @notice Set whitelister address.
*/
function setWhitelister(address whitelister) external onlyOwner {
_setWhitelister(whitelister);
}

/**
* @notice Remove an Alert.
* @param messageHash The message hash of the alert
Expand Down Expand Up @@ -339,10 +357,17 @@ contract MachServiceManager is
emit AlertConfirmerChanged(previousBatchConfirmer, alertConfirmer);
}

/// @notice changes the whitelister
function _setWhitelister(address _whitelister) internal {
address previousWhitelister = whitelister;
whitelister = _whitelister;
emit WhitelisterChanged(previousWhitelister, _whitelister);
}
/**
* @notice converts a alert header to a reduced alert header
* @param alertHeader the alert header to convert
*/

function _convertAlertHeaderToReducedAlertHeader(AlertHeader calldata alertHeader)
internal
pure
Expand Down
5 changes: 4 additions & 1 deletion contracts/src/core/MachServiceManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ abstract contract MachServiceManagerStorage {
/// @notice Resolved message hashes, prevent aggregator from replay any resolved alert
EnumerableSet.Bytes32Set internal _resolvedMessageHashes;

/// @notice Role for whitelisting operators
address public whitelister;

// storage gap for upgradeability
// slither-disable-next-line shadowing-state
uint256[45] private __GAP;
uint256[44] private __GAP;

constructor(uint256 _rollupChainId) {
rollupChainId = _rollupChainId;
Expand Down
1 change: 1 addition & 0 deletions contracts/src/error/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.12;
error ZeroAddress();
error InvalidStartIndex();
error InvalidConfirmer();
error NotWhitelister();
error InvalidSender();
error InvalidReferenceBlockNum();
error InsufficientThreshold();
Expand Down
7 changes: 7 additions & 0 deletions contracts/src/interfaces/IMachServiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ interface IMachServiceManager is IServiceManager {
*/
event AlertConfirmerChanged(address previousAddress, address newAddress);

/**
* @notice Emitted when the whitelister is changed.
* @param previousAddress The address of the previous whitelister
* @param newAddress The address of the new whitelister
*/
event WhitelisterChanged(address previousAddress, address newAddress);

/**
* @notice Emitted when the quorum threshold percentage is changed.
* @param thresholdPercentages The new quorum threshold percentage
Expand Down

0 comments on commit e0531e5

Please sign in to comment.