Skip to content

Commit

Permalink
feat: add requirement for operator to register to eigenlayer first
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenli86 committed Dec 8, 2023
1 parent 783797b commit 3e2ec06
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ contract DelegationManager is Initializable, OwnableUpgradeable, Pausable, Deleg
!operatorSaltIsSpent[operator][operatorSignature.salt],
"DelegationManager.registerOperatorToAVS: salt already spent"
);
require(
isOperator(operator),
"DelegationManager.registerOperatorToAVS: operator not registered to EigenLayer yet");

// Calculate the digest hash
bytes32 operatorRegistrationDigestHash = calculateOperatorAVSRegistrationDigestHash({
Expand Down
30 changes: 29 additions & 1 deletion src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,11 @@ contract DelegationManagerUnitTests_operatorAVSRegisterationStatus is Delegation

// @notice Verifies an operator registers successfull to avs and see an `OperatorAVSRegistrationStatusUpdated` event emitted
function testFuzz_registerOperatorToAVS(bytes32 salt) public {
cheats.expectEmit(true, true, true, true, address(delegationManager));
address operator = cheats.addr(delegationSignerPrivateKey);
assertFalse(delegationManager.isOperator(operator), "bad test setup");
_registerOperatorWithBaseDetails(operator);

cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorAVSRegistrationStatusUpdated(operator, defaultAVS, OperatorAVSRegistrationStatus.REGISTERED);

uint256 expiry = type(uint256).max;
Expand All @@ -623,9 +626,31 @@ contract DelegationManagerUnitTests_operatorAVSRegisterationStatus is Delegation
delegationManager.registerOperatorToAVS(operator, operatorSignature);
}

// @notice Verifies an operator registers successfull to avs and see an `OperatorAVSRegistrationStatusUpdated` event emitted
function testFuzz_revert_whenOperatorNotRegisteredToEigenLayerYet(bytes32 salt) public {
address operator = cheats.addr(delegationSignerPrivateKey);
assertFalse(delegationManager.isOperator(operator), "bad test setup");

cheats.prank(defaultAVS);
uint256 expiry = type(uint256).max;
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = _getOperatorSignature(
delegationSignerPrivateKey,
operator,
defaultAVS,
salt,
expiry
);

cheats.expectRevert("DelegationManager.registerOperatorToAVS: operator not registered to EigenLayer yet");
delegationManager.registerOperatorToAVS(operator, operatorSignature);
}

// @notice Verifies an operator registers fails when the signature is not from the operator
function testFuzz_revert_whenSignatureAddressIsNotOperator(bytes32 salt) public {
address operator = cheats.addr(delegationSignerPrivateKey);
assertFalse(delegationManager.isOperator(operator), "bad test setup");
_registerOperatorWithBaseDetails(operator);

uint256 expiry = type(uint256).max;
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = _getOperatorSignature(
delegationSignerPrivateKey,
Expand All @@ -652,6 +677,9 @@ contract DelegationManagerUnitTests_operatorAVSRegisterationStatus is Delegation
// @notice Verifies an operator registers fails when it's already registered to the avs
function testFuzz_revert_whenOperatorAlreadyRegisteredToAVS(bytes32 salt) public {
address operator = cheats.addr(delegationSignerPrivateKey);
assertFalse(delegationManager.isOperator(operator), "bad test setup");
_registerOperatorWithBaseDetails(operator);

uint256 expiry = type(uint256).max;
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = _getOperatorSignature(
delegationSignerPrivateKey,
Expand Down

0 comments on commit 3e2ec06

Please sign in to comment.