Skip to content

Commit 634a578

Browse files
committed
Registry params updated
1 parent fe0dee1 commit 634a578

File tree

1 file changed

+60
-61
lines changed

1 file changed

+60
-61
lines changed

src/Registry.sol

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ contract Registry is IRegistry {
1212
using BLS for *;
1313

1414
/// @notice Mapping from registration merkle roots to Operator structs
15-
mapping(bytes32 registrationRoot => Operator) public operators;
15+
mapping(bytes32 registrationRoot => Operator) public registrations;
1616

1717
/// @notice Mapping to track if a commitment slashing has occurred before with same input
18-
mapping(bytes32 commitmentSlashingDigest => bool) public commitmentSlashedBefore;
18+
mapping(bytes32 commitmentSlashingDigest => bool) public slashedBefore;
1919

2020
/// @notice Mapping to track if an equivocation slashing has occurred before with same input
2121
mapping(bytes32 equivocationSlashingDigest => bool) public equivocationSlashedBefore;
@@ -66,17 +66,17 @@ contract Registry is IRegistry {
6666
}
6767

6868
// Prevent reusing a deleted operator
69-
if (operators[registrationRoot].deleted) {
69+
if (registrations[registrationRoot].deleted) {
7070
revert OperatorDeleted();
7171
}
7272

7373
// Prevent duplicates from overwriting previous registrations
74-
if (operators[registrationRoot].registeredAt != 0) {
74+
if (registrations[registrationRoot].registeredAt != 0) {
7575
revert OperatorAlreadyRegistered();
7676
}
7777

7878
// Each Operator is mapped to a unique registration root
79-
Operator storage newOperator = operators[registrationRoot];
79+
Operator storage newOperator = registrations[registrationRoot];
8080
newOperator.owner = owner;
8181
newOperator.collateralWei = uint80(msg.value);
8282
newOperator.numKeys = uint16(regs.length);
@@ -86,7 +86,7 @@ contract Registry is IRegistry {
8686
newOperator.deleted = false;
8787
newOperator.equivocated = false;
8888

89-
// Add initial collateral record
89+
// Store the initial collateral value in the history
9090
newOperator.collateralHistory.push(
9191
CollateralRecord({ timestamp: uint64(block.number), collateralValue: uint80(msg.value) })
9292
);
@@ -102,7 +102,7 @@ contract Registry is IRegistry {
102102
/// @dev - The caller is not the operator's withdrawal address (WrongOperator)
103103
/// @param registrationRoot The merkle root generated and stored from the register() function
104104
function unregister(bytes32 registrationRoot) external {
105-
Operator storage operator = operators[registrationRoot];
105+
Operator storage operator = registrations[registrationRoot];
106106

107107
// Prevent reusing a deleted operator
108108
if (operator.deleted) {
@@ -143,7 +143,7 @@ contract Registry is IRegistry {
143143
/// @param committer The address of the key used for commitments
144144

145145
function optInToSlasher(bytes32 registrationRoot, address slasher, address committer) external {
146-
Operator storage operator = operators[registrationRoot];
146+
Operator storage operator = registrations[registrationRoot];
147147

148148
// Prevent reusing a deleted operator
149149
if (operator.deleted) {
@@ -189,7 +189,7 @@ contract Registry is IRegistry {
189189
/// @param registrationRoot The merkle root generated and stored from the register() function
190190
/// @param slasher The address of the Slasher contract to opt out of
191191
function optOutOfSlasher(bytes32 registrationRoot, address slasher) external {
192-
Operator storage operator = operators[registrationRoot];
192+
Operator storage operator = registrations[registrationRoot];
193193

194194
// Prevent reusing a deleted operator
195195
if (operator.deleted) {
@@ -258,7 +258,7 @@ contract Registry is IRegistry {
258258
ISlasher.SignedCommitment calldata commitment,
259259
bytes calldata evidence
260260
) external returns (uint256 slashAmountWei) {
261-
Operator storage operator = operators[registrationRoot];
261+
Operator storage operator = registrations[registrationRoot];
262262
bytes32 slashingDigest = keccak256(abi.encode(delegation, commitment, registrationRoot));
263263

264264
// Prevent reusing a deleted operator
@@ -267,7 +267,7 @@ contract Registry is IRegistry {
267267
}
268268

269269
// Prevent slashing with same inputs
270-
if (commitmentSlashedBefore[slashingDigest]) {
270+
if (slashedBefore[slashingDigest]) {
271271
revert SlashingAlreadyOccurred();
272272
}
273273

@@ -304,7 +304,7 @@ contract Registry is IRegistry {
304304
}
305305

306306
// Prevent same slashing from occurring again
307-
commitmentSlashedBefore[slashingDigest] = true;
307+
slashedBefore[slashingDigest] = true;
308308

309309
// Call the Slasher contract to slash the operator
310310
slashAmountWei = ISlasher(commitment.commitment.slasher).slash(
@@ -342,29 +342,26 @@ contract Registry is IRegistry {
342342
);
343343
}
344344

345-
/**
346-
* @notice Slashes an operator for breaking a commitment in a protocol they opted into via the optInToSlasher() function. The operator must have already opted into the protocol.
347-
* @dev The function verifies the commitment was signed by the registered committer from the optInToSlasher() function before calling into the Slasher contract.
348-
* @dev If the slash amount equals the operator's collateral, the operator will be implicitly unregistered (collateral becomes zero).
349-
* @dev Reverts if:
350-
* @dev - The operator has already been deleted (OperatorDeleted)
351-
* @dev - The fraud proof window has not passed (FraudProofWindowNotMet)
352-
* @dev - The operator has already unregistered and delay passed (OperatorAlreadyUnregistered)
353-
* @dev - The slash window has expired (SlashWindowExpired)
354-
* @dev - The operator has not opted into the slasher (NotOptedIn)
355-
* @dev - The commitment was not signed by registered committer (UnauthorizedCommitment)
356-
* @dev - The slash amount exceeds operator's collateral (SlashAmountExceedsCollateral)
357-
* @param registrationRoot The merkle root generated and stored from the register() function
358-
* @param commitment The SignedCommitment signed by the delegate's ECDSA key
359-
* @param evidence Arbitrary evidence to slash the operator, required by the Slasher contract
360-
* @return slashAmountWei The amount of WEI slashed
361-
*/
345+
/// @notice Slashes an operator for breaking a commitment in a protocol they opted into via the optInToSlasher() function. The operator must have already opted into the protocol.
346+
/// @dev The function verifies the commitment was signed by the registered committer from the optInToSlasher() function before calling into the Slasher contract.
347+
/// @dev Reverts if:
348+
/// @dev - The operator has already been deleted (OperatorDeleted)
349+
/// @dev - The fraud proof window has not passed (FraudProofWindowNotMet)
350+
/// @dev - The operator has already unregistered and delay passed (OperatorAlreadyUnregistered)
351+
/// @dev - The slash window has expired (SlashWindowExpired)
352+
/// @dev - The operator has not opted into the slasher (NotOptedIn)
353+
/// @dev - The commitment was not signed by registered committer (UnauthorizedCommitment)
354+
/// @dev - The slash amount exceeds operator's collateral (SlashAmountExceedsCollateral)
355+
/// @param registrationRoot The merkle root generated and stored from the register() function
356+
/// @param commitment The SignedCommitment signed by the delegate's ECDSA key
357+
/// @param evidence Arbitrary evidence to slash the operator, required by the Slasher contract
358+
/// @return slashAmountWei The amount of WEI slashed
362359
function slashCommitmentFromOptIn(
363360
bytes32 registrationRoot,
364361
ISlasher.SignedCommitment calldata commitment,
365362
bytes calldata evidence
366363
) external returns (uint256 slashAmountWei) {
367-
Operator storage operator = operators[registrationRoot];
364+
Operator storage operator = registrations[registrationRoot];
368365
address slasher = commitment.commitment.slasher;
369366

370367
// Prevent reusing a deleted operator
@@ -468,7 +465,7 @@ contract Registry is IRegistry {
468465
ISlasher.SignedDelegation calldata delegationOne,
469466
ISlasher.SignedDelegation calldata delegationTwo
470467
) external returns (uint256 slashAmountWei) {
471-
Operator storage operator = operators[registrationRoot];
468+
Operator storage operator = registrations[registrationRoot];
472469
bytes32 slashingDigest = keccak256(abi.encode(delegationOne, delegationTwo, registrationRoot));
473470

474471
// Prevent reusing a deleted operator
@@ -549,31 +546,33 @@ contract Registry is IRegistry {
549546
return slashAmountWei;
550547
}
551548

552-
/**
553-
* @notice Slashes an operator for fraudulently registering a BLS key
554-
* @dev The function verifies `proof` to first ensure the operator's BLS key is in the registry,
555-
* then verifies the `registrationSignature` was signed by the same key. If the fraud proof window
556-
* has passed, the operator's collateral is burned and the challenger is rewarded.
557-
* @dev If the slash amount equals the operator's collateral, the operator will be implicitly unregistered (collateral becomes zero).
558-
* @dev The function will revert if:
559-
* @dev - The operator has already been deleted (OperatorDeleted)
560-
* @dev - The fraud proof window has not passed (FraudProofWindowNotMet)
561-
* @dev - The operator has already unregistered (OperatorAlreadyUnregistered)
562-
* @dev - The proof is invalid (NotRegisteredKey)
563-
* @dev - The registration signature is invalid (DelegationSignatureInvalid)
564-
* @param registrationRoot The merkle root generated and stored from the register() function
565-
* @param reg The registration to verify
566-
* @param proof The merkle proof to verify the operator's key is in the registry
567-
* @param leafIndex The index of the leaf in the merkle tree
568-
* @return collateralWei The amount of WEI slashed
549+
/**
550+
*
551+
* Slashing Functions *
552+
*
569553
*/
554+
555+
/// @notice Slash an operator for submitting a fraudulent `Registration` in the register() function
556+
/// @dev To save BLS verification gas costs, the URC optimistically accepts registration signatures. This function allows a challenger to slash the operator by executing the BLS verification to prove the registration is fraudulent.
557+
/// @dev A successful challenge will transfer `MIN_COLLATERAL / 2` to the challenger, burn `MIN_COLLATERAL / 2`, and then allow the operator to claim their remaining collateral after `SLASH_WINDOW` blocks have elapsed from the `claimSlashedCollateral()` function.
558+
/// @dev The function will revert if:
559+
/// @dev - The operator has already been deleted (OperatorDeleted)
560+
/// @dev - The fraud proof window has expired (FraudProofWindowExpired)
561+
/// @dev - The operator has not registered (NotRegisteredKey)
562+
/// @dev - The proof is invalid (FraudProofChallengeInvalid)
563+
/// @dev - ETH transfer to challenger fails (EthTransferFailed)
564+
/// @param registrationRoot The merkle root generated and stored from the register() function
565+
/// @param reg The fraudulent Registration
566+
/// @param proof The merkle proof to verify the operator's key is in the registry
567+
/// @param leafIndex The index of the leaf in the merkle tree
568+
/// @return slashedCollateralWei The amount of GWEI slashed
570569
function slashRegistration(
571570
bytes32 registrationRoot,
572571
Registration calldata reg,
573572
bytes32[] calldata proof,
574573
uint256 leafIndex
575-
) external returns (uint256 collateralWei) {
576-
Operator storage operator = operators[registrationRoot];
574+
) external returns (uint256 slashedCollateralWei) {
575+
Operator storage operator = registrations[registrationRoot];
577576

578577
// Prevent reusing a deleted operator
579578
if (operator.deleted) {
@@ -593,17 +592,17 @@ contract Registry is IRegistry {
593592
}
594593

595594
// Verify the registration was signed by the operator's BLS key
596-
collateralWei =
595+
slashedCollateralWei =
597596
_verifyMerkleProof(registrationRoot, keccak256(abi.encode(reg, operator.owner)), proof, leafIndex);
598597

599598
// Burn half of the collateral and reward the challenger with the other half
600-
_rewardAndBurn(collateralWei / 2, msg.sender);
599+
_rewardAndBurn(slashedCollateralWei / 2, msg.sender);
601600

602601
// Mark the operator as deleted to prevent future slashings
603602
operator.deleted = true;
604603

605604
emit OperatorSlashed(
606-
SlashingType.Fraud, registrationRoot, operator.owner, msg.sender, address(0), collateralWei
605+
SlashingType.Fraud, registrationRoot, operator.owner, msg.sender, address(0), slashedCollateralWei
607606
);
608607
}
609608

@@ -620,7 +619,7 @@ contract Registry is IRegistry {
620619
/// @dev - The collateral amount overflows the `collateralGwei` field (CollateralOverflow)
621620
/// @param registrationRoot The merkle root generated and stored from the register() function
622621
function addCollateral(bytes32 registrationRoot) external payable {
623-
Operator storage operator = operators[registrationRoot];
622+
Operator storage operator = registrations[registrationRoot];
624623

625624
// Prevent reusing a deleted operator
626625
if (operator.deleted) {
@@ -656,7 +655,7 @@ contract Registry is IRegistry {
656655
/// @dev The function will transfer the operator's collateral to their registered `withdrawalAddress`.
657656
/// @param registrationRoot The merkle root generated and stored from the register() function
658657
function claimCollateral(bytes32 registrationRoot) external {
659-
Operator storage operator = operators[registrationRoot];
658+
Operator storage operator = registrations[registrationRoot];
660659
address operatorOwner = operator.owner;
661660
uint256 collateralWei = operator.collateralWei;
662661

@@ -707,7 +706,7 @@ contract Registry is IRegistry {
707706
/// @dev - The slash window has not passed (SlashWindowNotMet)
708707
/// @dev - ETH transfer to operator fails (EthTransferFailed)
709708
function claimSlashedCollateral(bytes32 registrationRoot) external {
710-
Operator storage operator = operators[registrationRoot];
709+
Operator storage operator = registrations[registrationRoot];
711710

712711
// Prevent reusing a deleted operator
713712
if (operator.deleted) {
@@ -752,7 +751,7 @@ contract Registry is IRegistry {
752751
view
753752
returns (uint256 collateralWei)
754753
{
755-
CollateralRecord[] storage records = operators[registrationRoot].collateralHistory;
754+
CollateralRecord[] storage records = registrations[registrationRoot].collateralHistory;
756755
if (records.length == 0) {
757756
return 0;
758757
}
@@ -810,7 +809,7 @@ contract Registry is IRegistry {
810809
view
811810
returns (SlasherCommitment memory slasherCommitment)
812811
{
813-
Operator storage operator = operators[registrationRoot];
812+
Operator storage operator = registrations[registrationRoot];
814813
if (operator.registeredAt == 0) {
815814
revert NotRegisteredKey();
816815
}
@@ -822,7 +821,7 @@ contract Registry is IRegistry {
822821
/// @param slasher The address of the slasher to check
823822
/// @return True if the operator is opted in, false otherwise
824823
function isOptedIntoSlasher(bytes32 registrationRoot, address slasher) external view returns (bool) {
825-
Operator storage operator = operators[registrationRoot];
824+
Operator storage operator = registrations[registrationRoot];
826825
if (operator.registeredAt == 0) {
827826
revert NotRegisteredKey();
828827
}
@@ -844,7 +843,7 @@ contract Registry is IRegistry {
844843
uint256 leafIndex,
845844
address slasher
846845
) external view returns (SlasherCommitment memory slasherCommitment, uint256 collateralWei) {
847-
Operator storage operator = operators[registrationRoot];
846+
Operator storage operator = registrations[registrationRoot];
848847
slasherCommitment = operator.slasherCommitments[slasher];
849848

850849
collateralWei = _verifyMerkleProof(registrationRoot, keccak256(abi.encode(reg)), proof, leafIndex);
@@ -892,7 +891,7 @@ contract Registry is IRegistry {
892891
if (!MerkleTree.verifyProofCalldata(registrationRoot, leaf, leafIndex, proof)) {
893892
revert InvalidMerkleProof();
894893
}
895-
collateralWei = operators[registrationRoot].collateralWei;
894+
collateralWei = registrations[registrationRoot].collateralWei;
896895
}
897896

898897
/// @notice Verifies a delegation was signed by a registered operator's key

0 commit comments

Comments
 (0)