Skip to content

Commit

Permalink
fix(contracts): msg.sender check on registerOperator
Browse files Browse the repository at this point in the history
  • Loading branch information
mempirate committed Oct 10, 2024
1 parent 27fafed commit 5fed1c4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
13 changes: 6 additions & 7 deletions bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,26 @@ contract BoltEigenLayerMiddleware is IBoltMiddleware, OwnableUpgradeable, UUPSUp
// ========= EIGENLAYER MIDDLEWARE LOGIC =========

/// @notice Allow an operator to signal opt-in to Bolt Protocol.
/// @param operator The operator address to signal opt-in for.
/// @dev This requires calling the EigenLayer AVS Directory contract to register the operator.
/// EigenLayer internally contains a mapping from `msg.sender` (our AVS contract) to the operator
/// EigenLayer internally contains a mapping from `msg.sender` (our AVS contract) to the operator.
/// The msg.sender of this call will be the operator address.
function registerOperator(
address operator,
string calldata rpc,
ISignatureUtils.SignatureWithSaltAndExpiry calldata operatorSignature
) public {
if (boltManager.isOperator(operator)) {
if (boltManager.isOperator(msg.sender)) {
revert AlreadyRegistered();
}

if (!DELEGATION_MANAGER.isOperator(operator)) {
if (!DELEGATION_MANAGER.isOperator(msg.sender)) {
revert NotOperator();
}

// Register the operator to the AVS directory for this AVS
AVS_DIRECTORY.registerOperatorToAVS(operator, operatorSignature);
AVS_DIRECTORY.registerOperatorToAVS(msg.sender, operatorSignature);

// Register the operator in the manager
boltManager.registerOperator(operator, rpc);
boltManager.registerOperator(msg.sender, rpc);
}

/// @notice Deregister an EigenLayer layer operator from working in Bolt Protocol.
Expand Down
5 changes: 2 additions & 3 deletions bolt-contracts/src/contracts/BoltManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,10 @@ contract BoltManager is IBoltManager, OwnableUpgradeable, UUPSUpgradeable {
revert OperatorAlreadyRegistered();
}

// Timestamp will be set when we enable the operator below
Operator memory operator = Operator(rpc, msg.sender, 0);
// Create an already enabled operator
Operator memory operator = Operator(rpc, msg.sender, Time.timestamp());

operators.set(operatorAddr, operator);
operators.enable(operatorAddr);
}

/// @notice De-registers an operator from Bolt. Only callable by a supported middleware contract.
Expand Down
14 changes: 8 additions & 6 deletions bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,23 @@ contract BoltSymbioticMiddleware is IBoltMiddleware, OwnableUpgradeable, UUPSUpg
// ========= SYMBIOTIC MIDDLEWARE LOGIC =========

/// @notice Allow an operator to signal opt-in to Bolt Protocol.
/// @param operator The operator address to signal opt-in for.
function registerOperator(address operator, string calldata rpc) public {
if (boltManager.isOperator(operator)) {
/// msg.sender must be an operator in the Symbiotic network.
function registerOperator(
string calldata rpc
) public {
if (boltManager.isOperator(msg.sender)) {
revert AlreadyRegistered();
}

if (!IRegistry(OPERATOR_REGISTRY).isEntity(operator)) {
if (!IRegistry(OPERATOR_REGISTRY).isEntity(msg.sender)) {
revert NotOperator();
}

if (!IOptInService(OPERATOR_NET_OPTIN).isOptedIn(operator, BOLT_SYMBIOTIC_NETWORK)) {
if (!IOptInService(OPERATOR_NET_OPTIN).isOptedIn(msg.sender, BOLT_SYMBIOTIC_NETWORK)) {
revert OperatorNotOptedIn();
}

boltManager.registerOperator(operator, rpc);
boltManager.registerOperator(msg.sender, rpc);
}

/// @notice Deregister a Symbiotic operator from working in Bolt Protocol.
Expand Down
4 changes: 3 additions & 1 deletion bolt-contracts/test/BoltManager.EigenLayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ contract BoltManagerEigenLayerTest is Test {
emit IAVSDirectory.OperatorAVSRegistrationStatusUpdated(
operator, address(middleware), IAVSDirectory.OperatorAVSRegistrationStatus.REGISTERED
);
middleware.registerOperator(operator, "https://bolt-rpc.io", operatorSignature);

vm.prank(operator);
middleware.registerOperator("https://bolt-rpc.io", operatorSignature);

assertEq(manager.isOperatorEnabled(operator), true);

Expand Down
3 changes: 2 additions & 1 deletion bolt-contracts/test/BoltManager.Symbiotic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ contract BoltManagerSymbioticTest is Test {
middleware.registerVault(address(vault));
assertEq(middleware.isVaultEnabled(address(vault)), true);

middleware.registerOperator(operator, "https://bolt-rpc.io");
vm.prank(operator);
middleware.registerOperator("https://bolt-rpc.io");
assertEq(manager.isOperatorEnabled(operator), true);

// --- Set the stake limit for the Vault ---
Expand Down

0 comments on commit 5fed1c4

Please sign in to comment.