From 5fed1c46ae2f4ebaf6c331c0e1db55b208af8baf Mon Sep 17 00:00:00 2001 From: Jonas Bostoen Date: Thu, 10 Oct 2024 10:27:28 +0200 Subject: [PATCH] fix(contracts): msg.sender check on registerOperator --- .../src/contracts/BoltEigenLayerMiddleware.sol | 13 ++++++------- bolt-contracts/src/contracts/BoltManager.sol | 5 ++--- .../src/contracts/BoltSymbioticMiddleware.sol | 14 ++++++++------ bolt-contracts/test/BoltManager.EigenLayer.t.sol | 4 +++- bolt-contracts/test/BoltManager.Symbiotic.t.sol | 3 ++- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol b/bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol index dc1d230c..f9f9af26 100644 --- a/bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol +++ b/bolt-contracts/src/contracts/BoltEigenLayerMiddleware.sol @@ -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. diff --git a/bolt-contracts/src/contracts/BoltManager.sol b/bolt-contracts/src/contracts/BoltManager.sol index cb2e6c07..6d821a31 100644 --- a/bolt-contracts/src/contracts/BoltManager.sol +++ b/bolt-contracts/src/contracts/BoltManager.sol @@ -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. diff --git a/bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol b/bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol index ce15fb2b..57c4e40c 100644 --- a/bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol +++ b/bolt-contracts/src/contracts/BoltSymbioticMiddleware.sol @@ -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. diff --git a/bolt-contracts/test/BoltManager.EigenLayer.t.sol b/bolt-contracts/test/BoltManager.EigenLayer.t.sol index 2426244e..85d9bf17 100644 --- a/bolt-contracts/test/BoltManager.EigenLayer.t.sol +++ b/bolt-contracts/test/BoltManager.EigenLayer.t.sol @@ -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); diff --git a/bolt-contracts/test/BoltManager.Symbiotic.t.sol b/bolt-contracts/test/BoltManager.Symbiotic.t.sol index 1fc00157..b5be662c 100644 --- a/bolt-contracts/test/BoltManager.Symbiotic.t.sol +++ b/bolt-contracts/test/BoltManager.Symbiotic.t.sol @@ -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 ---