-
Notifications
You must be signed in to change notification settings - Fork 437
Feat/operator sets #579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/operator sets #579
Changes from 1 commit
5dbd94a
51ff168
d477943
bcf7d21
3ff5cb6
b31d4ed
73cf5e2
5d6a28c
e94c74b
331afaa
b4724c0
17e9f78
6bcc71c
08aa8fc
0b07f47
97a6dba
e9359ad
b92b285
18c7133
b869392
c4437c6
5d09658
648cc94
d8c046f
d12ea4c
c926f2f
92479e2
27ed1a1
3b0450e
5f90d78
f4c3ae5
c190c1b
3b984ab
b944193
98d0c4f
d83a870
1fa4a42
1e9609f
1328e23
0553d18
22ceb9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ import "src/test/utils/EigenLayerUnitTestSetup.sol"; | |
* Contracts not mocked: DelegationManager | ||
*/ | ||
contract AVSDirectoryUnitTests is EigenLayerUnitTestSetup, IAVSDirectoryEvents { | ||
uint256 internal constant MAX_PRIVATE_KEY = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140; | ||
|
||
// Contract under test | ||
AVSDirectory avsDirectory; | ||
AVSDirectory avsDirectoryImplementation; | ||
|
@@ -170,14 +172,137 @@ contract AVSDirectoryUnitTests is EigenLayerUnitTestSetup, IAVSDirectoryEvents { | |
} | ||
} | ||
|
||
contract AVSDirectoryUnitTests_registerOperatorToOperatorSet is AVSDirectoryUnitTests { | ||
event OperatorAddedToOperatorSet(address operator, IAVSDirectory.OperatorSet operatorSet); | ||
|
||
function testFuzz_revert_SignatureIsExpired( | ||
address operator, | ||
uint32 oid, | ||
bytes32 salt, | ||
uint256 expiry | ||
) public virtual { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might want to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for all fuzzed address inputs, we get a couple flakey fuzz tests in our CI occasionally when we forget this modifier |
||
expiry = bound(expiry, 0, type(uint256).max - 1); | ||
|
||
cheats.warp(type(uint256).max); | ||
cheats.expectRevert("AVSDirectory.registerOperatorToOperatorSet: operator signature expired"); | ||
|
||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, oid, ISignatureUtils.SignatureWithSaltAndExpiry(new bytes(0), salt, expiry) | ||
); | ||
} | ||
|
||
function testFuzz_revert_OperatorRegistered( | ||
uint256 operatorPk, | ||
uint32 oid, | ||
bytes32 salt, | ||
uint256 expiry | ||
) public virtual { | ||
operatorPk = bound(operatorPk, 1, MAX_PRIVATE_KEY); | ||
expiry = bound(expiry, 1, type(uint256).max); | ||
|
||
cheats.warp(0); | ||
|
||
address operator = cheats.addr(operatorPk); | ||
(uint8 v, bytes32 r, bytes32 s) = cheats.sign( | ||
operatorPk, avsDirectory.calculateOperatorAVSRegistrationDigestHash(operator, address(this), salt, expiry) | ||
); | ||
|
||
_registerOperatorWithBaseDetails(operator); | ||
|
||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, oid, ISignatureUtils.SignatureWithSaltAndExpiry(abi.encodePacked(r, s, v), salt, expiry) | ||
); | ||
|
||
cheats.expectRevert("AVSDirectory.registerOperatorToOperatorSet: operator already registered to operator set"); | ||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, oid, ISignatureUtils.SignatureWithSaltAndExpiry(new bytes(0), salt, expiry) | ||
); | ||
} | ||
|
||
function testFuzz_revert_OperatorNotRegistered( | ||
address operator, | ||
uint32 oid, | ||
bytes32 salt, | ||
uint256 expiry | ||
) public virtual { | ||
vm.assume(operator != address(0)); | ||
|
||
expiry = bound(expiry, 1, type(uint256).max); | ||
|
||
cheats.warp(0); | ||
|
||
cheats.expectRevert("AVSDirectory.registerOperatorToAVS: operator not registered to EigenLayer yet"); | ||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, oid, ISignatureUtils.SignatureWithSaltAndExpiry(new bytes(0), salt, expiry) | ||
); | ||
} | ||
|
||
function testFuzz_revert_SaltSpent(uint256 operatorPk, uint32 oid, bytes32 salt, uint256 expiry) public virtual { | ||
oid = uint32(bound(oid, 1, type(uint32).max)); | ||
operatorPk = bound(operatorPk, 1, MAX_PRIVATE_KEY); | ||
expiry = bound(expiry, 1, type(uint256).max); | ||
|
||
cheats.warp(0); | ||
|
||
address operator = cheats.addr(operatorPk); | ||
(uint8 v, bytes32 r, bytes32 s) = cheats.sign( | ||
operatorPk, avsDirectory.calculateOperatorAVSRegistrationDigestHash(operator, address(this), salt, expiry) | ||
); | ||
|
||
_registerOperatorWithBaseDetails(operator); | ||
|
||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, oid, ISignatureUtils.SignatureWithSaltAndExpiry(abi.encodePacked(r, s, v), salt, expiry) | ||
); | ||
|
||
cheats.expectRevert("AVSDirectory.registerOperatorToAVS: salt already spent"); | ||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, 0, ISignatureUtils.SignatureWithSaltAndExpiry(new bytes(0), salt, expiry) | ||
); | ||
} | ||
|
||
function testFuzz_Correctness(uint256 operatorPk, uint32 oid, bytes32 salt, uint256 expiry) public virtual { | ||
operatorPk = bound(operatorPk, 1, MAX_PRIVATE_KEY); | ||
expiry = bound(expiry, 1, type(uint256).max); | ||
|
||
cheats.warp(0); | ||
|
||
address operator = cheats.addr(operatorPk); | ||
(uint8 v, bytes32 r, bytes32 s) = cheats.sign( | ||
operatorPk, avsDirectory.calculateOperatorAVSRegistrationDigestHash(operator, address(this), salt, expiry) | ||
); | ||
|
||
_registerOperatorWithBaseDetails(operator); | ||
|
||
cheats.expectEmit(true, false, false, false, address(avsDirectory)); | ||
emit OperatorAVSRegistrationStatusUpdated( | ||
operator, address(this), IAVSDirectory.OperatorAVSRegistrationStatus.REGISTERED | ||
); | ||
|
||
cheats.expectEmit(true, false, false, false, address(avsDirectory)); | ||
emit OperatorAddedToOperatorSet(operator, IAVSDirectory.OperatorSet(address(this), oid)); | ||
avsDirectory.registerOperatorToOperatorSet( | ||
operator, oid, ISignatureUtils.SignatureWithSaltAndExpiry(abi.encodePacked(r, s, v), salt, expiry) | ||
); | ||
|
||
assertEq(avsDirectory.operatorAVSOperatorSetCount(address(this), operator), 1); | ||
assertEq(uint8(avsDirectory.avsOperatorStatus(address(this), operator)), 1); | ||
assertTrue(avsDirectory.operatorSetRegistrations(address(this), operator, oid)); | ||
assertTrue(avsDirectory.operatorSaltIsSpent(operator, salt)); | ||
assertTrue(avsDirectory.isOperatorSetAVS(address(this))); | ||
} | ||
} | ||
|
||
contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUnitTests { | ||
function test_revert_whenRegisterDeregisterToAVSPaused() public { | ||
// set the pausing flag | ||
cheats.prank(pauser); | ||
avsDirectory.pause(2 ** PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS); | ||
|
||
cheats.expectRevert("Pausable: index is paused"); | ||
avsDirectory.registerOperatorToAVS(address(0), ISignatureUtils.SignatureWithSaltAndExpiry(abi.encodePacked(""), 0, 0)); | ||
avsDirectory.registerOperatorToAVS( | ||
address(0), ISignatureUtils.SignatureWithSaltAndExpiry(abi.encodePacked(""), 0, 0) | ||
); | ||
|
||
cheats.expectRevert("Pausable: index is paused"); | ||
avsDirectory.deregisterOperatorFromAVS(address(0)); | ||
|
@@ -242,9 +367,9 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni | |
} | ||
|
||
// @notice Verifies an operator registers fails when the signature expiry already expires | ||
function testFuzz_revert_whenExpiryHasExpired( | ||
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature | ||
) public { | ||
function testFuzz_revert_whenExpiryHasExpired(ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature) | ||
public | ||
{ | ||
address operator = cheats.addr(delegationSignerPrivateKey); | ||
operatorSignature.expiry = bound(operatorSignature.expiry, 0, block.timestamp - 1); | ||
|
||
|
@@ -283,10 +408,14 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni | |
avsDirectory.cancelSalt(salt); | ||
|
||
assertTrue(avsDirectory.operatorSaltIsSpent(operator, salt), "salt was not successfully cancelled"); | ||
assertFalse(avsDirectory.operatorSaltIsSpent(defaultAVS, salt), "salt should only be cancelled for the operator"); | ||
assertFalse( | ||
avsDirectory.operatorSaltIsSpent(defaultAVS, salt), "salt should only be cancelled for the operator" | ||
); | ||
|
||
bytes32 newSalt; | ||
unchecked { newSalt = bytes32(uint(salt) + 1); } | ||
bytes32 newSalt; | ||
unchecked { | ||
newSalt = bytes32(uint256(salt) + 1); | ||
} | ||
|
||
assertFalse(salt == newSalt, "bad test setup"); | ||
|
||
|
@@ -321,9 +450,9 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni | |
assertFalse(delegationManager.isOperator(operator), "bad test setup"); | ||
_registerOperatorWithBaseDetails(operator); | ||
|
||
uint256 expiry = type(uint256).max; | ||
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = | ||
_getOperatorSignature(delegationSignerPrivateKey, operator, defaultAVS, salt, expiry); | ||
// uint256 expiry = type(uint256).max; | ||
// ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature = | ||
// _getOperatorSignature(delegationSignerPrivateKey, operator, defaultAVS, salt, expiry); | ||
|
||
cheats.startPrank(operator); | ||
avsDirectory.cancelSalt(salt); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: import events from IAVSDirectoryEvents