Skip to content
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: reregistration delay #246

Merged
merged 9 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/RegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ contract RegistryCoordinator is
operator: operator,
quorumNumbers: quorumNumbers
});
lastEjectionTimestamp[operator] = block.timestamp;
}

/*******************************************************************************
Expand Down Expand Up @@ -423,6 +424,16 @@ contract RegistryCoordinator is
_setEjector(_ejector);
}

/**
* @notice Sets the reregistration delay, which is the time an operator must wait after
* ejection before registering for any quorum
* @param _reregistrationDelay the new reregistration delay
* @dev only callable by the owner
*/
function setReregistrationDelay(uint256 _reregistrationDelay) external onlyOwner {
reregistrationDelay = _reregistrationDelay;
ChaoticWalrus marked this conversation as resolved.
Show resolved Hide resolved
}

/*******************************************************************************
INTERNAL FUNCTIONS
*******************************************************************************/
Expand Down Expand Up @@ -457,6 +468,9 @@ contract RegistryCoordinator is
require(quorumsToAdd.noBitsInCommon(currentBitmap), "RegistryCoordinator._registerOperator: operator already registered for some quorums being registered for");
uint192 newBitmap = uint192(currentBitmap.plus(quorumsToAdd));

// Check that the operator can reregister if ejected
require(lastEjectionTimestamp[operator] + reregistrationDelay < block.timestamp, "RegistryCoordinator._registerOperator: operator cannot reregister yet");

/**
* Update operator's bitmap, socket, and status. Only update operatorInfo if needed:
* if we're `REGISTERED`, the operatorId and status are already correct.
Expand Down
7 changes: 6 additions & 1 deletion src/RegistryCoordinatorStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ abstract contract RegistryCoordinatorStorage is IRegistryCoordinator {
/// @notice the address of the entity allowed to eject operators from the AVS
address public ejector;

/// @notice the last timestamp an operator was ejected
mapping(address => uint256) public lastEjectionTimestamp;
/// @notice the delay before an operator can reregister after being ejected
ChaoticWalrus marked this conversation as resolved.
Show resolved Hide resolved
uint256 public reregistrationDelay;

constructor(
IServiceManager _serviceManager,
IStakeRegistry _stakeRegistry,
Expand All @@ -78,5 +83,5 @@ abstract contract RegistryCoordinatorStorage is IRegistryCoordinator {

// storage gap for upgradeability
// slither-disable-next-line shadowing-state
uint256[41] private __GAP;
uint256[39] private __GAP;
}
2 changes: 2 additions & 0 deletions test/integration/User.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ contract User is Test {
function registerOperator(bytes calldata quorums) public createSnapshot virtual returns (bytes32) {
_log("registerOperator", quorums);

vm.warp(block.timestamp + 1);
registryCoordinator.registerOperator({
quorumNumbers: quorums,
socket: NAME,
Expand Down Expand Up @@ -208,6 +209,7 @@ contract User is Test {
expiry: expiry
});

vm.warp(block.timestamp + 1);
registryCoordinator.registerOperatorWithChurn({
quorumNumbers: allQuorums,
socket: NAME,
Expand Down
2 changes: 2 additions & 0 deletions test/unit/EjectionManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ contract EjectionManagerUnitTests is MockAVSDeployer {

testEjectOperators_MultipleOperatorInsideRatelimit();

vm.warp(block.timestamp + 1);

_registerOperaters(operatorsToEject, stake);

vm.warp(block.timestamp + ratelimitWindow);
Expand Down
56 changes: 56 additions & 0 deletions test/unit/RegistryCoordinatorUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,62 @@ contract RegistryCoordinatorUnitTests_DeregisterOperator_EjectOperator is Regist
registryCoordinator._deregisterOperatorExternal(defaultOperator, incorrectQuorum);
}

function test_reregisterOperator_revert_reregistrationDelay() public {
uint256 reregistrationDelay = 1 days;
cheats.warp(block.timestamp + reregistrationDelay);
cheats.prank(registryCoordinatorOwner);
registryCoordinator.setReregistrationDelay(reregistrationDelay);

ISignatureUtils.SignatureWithSaltAndExpiry memory emptySig;
uint32 registrationBlockNumber = 100;
uint32 reregistrationBlockNumber = 200;

bytes memory quorumNumbers = new bytes(1);
quorumNumbers[0] = bytes1(defaultQuorumNumber);

_setOperatorWeight(defaultOperator, uint8(quorumNumbers[0]), defaultStake);

cheats.prank(defaultOperator);
cheats.roll(registrationBlockNumber);
registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySig);

cheats.prank(ejector);
registryCoordinator.ejectOperator(defaultOperator, quorumNumbers);

cheats.prank(defaultOperator);
cheats.roll(reregistrationBlockNumber);
cheats.expectRevert("RegistryCoordinator._registerOperator: operator cannot reregister yet");
registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySig);
}

function test_reregisterOperator_reregistrationDelay() public {
uint256 reregistrationDelay = 1 days;
cheats.warp(block.timestamp + reregistrationDelay);
cheats.prank(registryCoordinatorOwner);
registryCoordinator.setReregistrationDelay(reregistrationDelay);

ISignatureUtils.SignatureWithSaltAndExpiry memory emptySig;
uint32 registrationBlockNumber = 100;
uint32 reregistrationBlockNumber = 200;

bytes memory quorumNumbers = new bytes(1);
quorumNumbers[0] = bytes1(defaultQuorumNumber);

_setOperatorWeight(defaultOperator, uint8(quorumNumbers[0]), defaultStake);

cheats.prank(defaultOperator);
cheats.roll(registrationBlockNumber);
registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySig);

cheats.prank(ejector);
registryCoordinator.ejectOperator(defaultOperator, quorumNumbers);

cheats.prank(defaultOperator);
cheats.roll(reregistrationBlockNumber);
cheats.warp(block.timestamp + reregistrationDelay + 1);
registryCoordinator.registerOperator(quorumNumbers, defaultSocket, pubkeyRegistrationParams, emptySig);
}

// note: this is not possible to test, because there is no route to getting the operator registered for nonexistent quorums
// function test_deregisterOperatorExternal_revert_nonexistentQuorums() public {

Expand Down
Loading