Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bf-N06' into ra/consensus-review…
Browse files Browse the repository at this point in the history
…-merged-fixes
  • Loading branch information
Raid Ateir committed Oct 30, 2024
2 parents 53b807a + 4e63a5d commit 25ad9a1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 17 deletions.
62 changes: 49 additions & 13 deletions l2-contracts/contracts/ConsensusRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg
/// @dev Fails if node owner already exists.
/// @dev Fails if a validator/attester with the same public key already exists.
/// @param _nodeOwner The address of the new node's owner.
/// @param _validatorWeight The voting weight of the validator, must be greater than 0.
/// @param _isValidatorActive A flag stating if the validator starts activated.
/// @param _validatorWeight The voting weight of the validator.
/// @param _validatorPubKey The BLS12-381 public key of the validator.
/// @param _validatorPoP The proof-of-possession (PoP) of the validator's public key.
/// @param _attesterWeight The voting weight of the attester, must be greater than 0.
/// @param _isAttesterActive A flag stating if the attester starts activated.
/// @param _attesterWeight The voting weight of the attester.
/// @param _attesterPubKey The ECDSA public key of the attester.
function add(
address _nodeOwner,
bool _isValidatorActive,
uint32 _validatorWeight,
BLS12_381PublicKey calldata _validatorPubKey,
BLS12_381Signature calldata _validatorPoP,
bool _isAttesterActive,
uint32 _attesterWeight,
Secp256k1PublicKey calldata _attesterPubKey
) external onlyOwner {
Expand All @@ -95,8 +99,8 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg
nodeOwners.push(_nodeOwner);
nodes[_nodeOwner] = Node({
attesterLatest: AttesterAttr({
active: true,
removed: false,
active: _isAttesterActive,
weight: _attesterWeight,
pubKey: _attesterPubKey
}),
Expand All @@ -108,8 +112,8 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg
}),
attesterLastUpdateCommit: attestersCommit,
validatorLatest: ValidatorAttr({
active: true,
removed: false,
active: _isValidatorActive,
weight: _validatorWeight,
pubKey: _validatorPubKey,
proofOfPossession: _validatorPoP
Expand All @@ -129,19 +133,21 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg

emit NodeAdded({
nodeOwner: _nodeOwner,
isValidatorActive: _isValidatorActive,
validatorWeight: _validatorWeight,
validatorPubKey: _validatorPubKey,
validatorPoP: _validatorPoP,
isAttesterActive: _isAttesterActive,
attesterWeight: _attesterWeight,
attesterPubKey: _attesterPubKey
});
}

/// @notice Deactivates a node, preventing it from participating in committees.
/// @notice Deactivates an attester, preventing it from participating in attester committees.
/// @dev Only callable by the contract owner or the node owner.
/// @dev Verifies that the node owner exists in the registry.
/// @param _nodeOwner The address of the node's owner to be inactivated.
function deactivate(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) {
function deactivateAttester(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) {
_verifyNodeOwnerExists(_nodeOwner);
(Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner);
if (deleted) {
Expand All @@ -150,17 +156,32 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg

_snapshotAttesterIfOutdated(node);
node.attesterLatest.active = false;
_snapshotValidatorIfOutdated(node);
node.validatorLatest.active = false;

emit NodeDeactivated(_nodeOwner);
emit AttesterDeactivated(_nodeOwner);
}

/// @notice Activates a previously inactive node, allowing it to participate in committees.
/// @notice Deactivates a validator, preventing it from participating in validator committees.
/// @dev Only callable by the contract owner or the node owner.
/// @dev Verifies that the node owner exists in the registry.
/// @param _nodeOwner The address of the node's owner to be inactivated.
function deactivateValidator(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) {
_verifyNodeOwnerExists(_nodeOwner);
(Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner);
if (deleted) {
return;
}

_snapshotValidatorIfOutdated(_node);
node.validatorLatest.active = false;

emit ValidatorDeactivated(_nodeOwner);
}

/// @notice Activates a previously inactive attester, allowing it to participate in attester committees.
/// @dev Only callable by the contract owner.
/// @dev Verifies that the node owner exists in the registry.
/// @param _nodeOwner The address of the node's owner to be activated.
function activate(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) {
function activateAttester(address _nodeOwner) external onlyOwner {
_verifyNodeOwnerExists(_nodeOwner);
(Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner);
if (deleted) {
Expand All @@ -169,10 +190,25 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg

_snapshotAttesterIfOutdated(node);
node.attesterLatest.active = true;
_snapshotValidatorIfOutdated(node);

emit AttesterActivated(_nodeOwner);
}

/// @notice Activates a previously inactive validator, allowing it to participate in validator committees.
/// @dev Only callable by the contract owner.
/// @dev Verifies that the node owner exists in the registry.
/// @param _nodeOwner The address of the node's owner to be activated.
function activateValidator(address _nodeOwner) external onlyOwner {
_verifyNodeOwnerExists(_nodeOwner);
(Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner);
if (deleted) {
return;
}

_snapshotValidatorIfOutdated(_node);
node.validatorLatest.active = true;

emit NodeActivated(_nodeOwner);
emit ValidatorActivated(_nodeOwner);
}

/// @notice Removes a node from the registry.
Expand Down
18 changes: 14 additions & 4 deletions l2-contracts/contracts/interfaces/IConsensusRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,18 @@ interface IConsensusRegistry {

event NodeAdded(
address indexed nodeOwner,
bool isValidatorActive,
uint32 validatorWeight,
BLS12_381PublicKey validatorPubKey,
BLS12_381Signature validatorPoP,
bool isAttesterActive,
uint32 attesterWeight,
Secp256k1PublicKey attesterPubKey
);
event NodeDeactivated(address indexed nodeOwner);
event NodeActivated(address indexed nodeOwner);
event AttesterDeactivated(address indexed nodeOwner);
event ValidatorDeactivated(address indexed nodeOwner);
event AttesterActivated(address indexed nodeOwner);
event ValidatorActivated(address indexed nodeOwner);
event NodeRemoved(address indexed nodeOwner);
event NodeDeleted(address indexed nodeOwner);
event NodeValidatorWeightChanged(address indexed nodeOwner, uint32 newWeight);
Expand All @@ -126,16 +130,22 @@ interface IConsensusRegistry {

function add(
address _nodeOwner,
bool _isValidatorActive,
uint32 _validatorWeight,
BLS12_381PublicKey calldata _validatorPubKey,
BLS12_381Signature calldata _validatorPoP,
bool _isAttesterActive,
uint32 _attesterWeight,
Secp256k1PublicKey calldata _attesterPubKey
) external;

function deactivate(address _nodeOwner) external;
function deactivateAttester(address _nodeOwner) external;

function activate(address _nodeOwner) external;
function deactivateValidator(address _nodeOwner) external;

function activateAttester(address _nodeOwner) external;

function activateValidator(address _nodeOwner) external;

function remove(address _nodeOwner) external;

Expand Down

0 comments on commit 25ad9a1

Please sign in to comment.