From 2893cf51bd9163e1b536b68b85723b377e81d1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Fran=C3=A7a?= Date: Thu, 10 Oct 2024 01:42:19 +0100 Subject: [PATCH 1/2] Fix --- l2-contracts/contracts/ConsensusRegistry.sol | 56 +++++++++++++++---- .../interfaces/IConsensusRegistry.sol | 18 ++++-- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/l2-contracts/contracts/ConsensusRegistry.sol b/l2-contracts/contracts/ConsensusRegistry.sol index de5af6340..37711c031 100644 --- a/l2-contracts/contracts/ConsensusRegistry.sol +++ b/l2-contracts/contracts/ConsensusRegistry.sol @@ -47,16 +47,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 _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 _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 { @@ -77,8 +81,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 }), @@ -90,8 +94,8 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg }), attesterLastUpdateCommit: attestersCommit, validatorLatest: ValidatorAttr({ - active: true, removed: false, + active: _isValidatorActive, weight: _validatorWeight, pubKey: _validatorPubKey, proofOfPossession: _validatorPoP @@ -111,19 +115,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 deactivate_attester(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) { _verifyNodeOwnerExists(_nodeOwner); (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); if (deleted) { @@ -132,17 +138,32 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg _ensureAttesterSnapshot(node); node.attesterLatest.active = false; - _ensureValidatorSnapshot(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 deactivate_validator(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) { + _verifyNodeOwnerExists(_nodeOwner); + (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); + if (deleted) { + return; + } + + _ensureValidatorSnapshot(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 activate_attester(address _nodeOwner) external onlyOwner { _verifyNodeOwnerExists(_nodeOwner); (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); if (deleted) { @@ -151,10 +172,25 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg _ensureAttesterSnapshot(node); node.attesterLatest.active = true; + + 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 activate_validator(address _nodeOwner) external onlyOwner { + _verifyNodeOwnerExists(_nodeOwner); + (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); + if (deleted) { + return; + } + _ensureValidatorSnapshot(node); node.validatorLatest.active = true; - emit NodeActivated(_nodeOwner); + emit ValidatorActivated(_nodeOwner); } /// @notice Removes a node from the registry. diff --git a/l2-contracts/contracts/interfaces/IConsensusRegistry.sol b/l2-contracts/contracts/interfaces/IConsensusRegistry.sol index a5e017484..45fb86e1c 100644 --- a/l2-contracts/contracts/interfaces/IConsensusRegistry.sol +++ b/l2-contracts/contracts/interfaces/IConsensusRegistry.sol @@ -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); @@ -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 deactivate_attester(address _nodeOwner) external; - function activate(address _nodeOwner) external; + function deactivate_validator(address _nodeOwner) external; + + function activate_attester(address _nodeOwner) external; + + function activate_validator(address _nodeOwner) external; function remove(address _nodeOwner) external; From 41c8e99c604e3b4e2d63540abd99c31dc6929f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Fran=C3=A7a?= Date: Mon, 14 Oct 2024 14:47:48 +0100 Subject: [PATCH 2/2] Camel case. --- l2-contracts/contracts/ConsensusRegistry.sol | 8 ++++---- l2-contracts/contracts/interfaces/IConsensusRegistry.sol | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/l2-contracts/contracts/ConsensusRegistry.sol b/l2-contracts/contracts/ConsensusRegistry.sol index 37711c031..fc48aa3ef 100644 --- a/l2-contracts/contracts/ConsensusRegistry.sol +++ b/l2-contracts/contracts/ConsensusRegistry.sol @@ -129,7 +129,7 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg /// @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_attester(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) { + function deactivateAttester(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) { _verifyNodeOwnerExists(_nodeOwner); (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); if (deleted) { @@ -146,7 +146,7 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg /// @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_validator(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) { + function deactivateValidator(address _nodeOwner) external onlyOwnerOrNodeOwner(_nodeOwner) { _verifyNodeOwnerExists(_nodeOwner); (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); if (deleted) { @@ -163,7 +163,7 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg /// @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_attester(address _nodeOwner) external onlyOwner { + function activateAttester(address _nodeOwner) external onlyOwner { _verifyNodeOwnerExists(_nodeOwner); (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); if (deleted) { @@ -180,7 +180,7 @@ contract ConsensusRegistry is IConsensusRegistry, Initializable, Ownable2StepUpg /// @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_validator(address _nodeOwner) external onlyOwner { + function activateValidator(address _nodeOwner) external onlyOwner { _verifyNodeOwnerExists(_nodeOwner); (Node storage node, bool deleted) = _getNodeAndDeleteIfRequired(_nodeOwner); if (deleted) { diff --git a/l2-contracts/contracts/interfaces/IConsensusRegistry.sol b/l2-contracts/contracts/interfaces/IConsensusRegistry.sol index 45fb86e1c..c41025c20 100644 --- a/l2-contracts/contracts/interfaces/IConsensusRegistry.sol +++ b/l2-contracts/contracts/interfaces/IConsensusRegistry.sol @@ -139,13 +139,13 @@ interface IConsensusRegistry { Secp256k1PublicKey calldata _attesterPubKey ) external; - function deactivate_attester(address _nodeOwner) external; + function deactivateAttester(address _nodeOwner) external; - function deactivate_validator(address _nodeOwner) external; + function deactivateValidator(address _nodeOwner) external; - function activate_attester(address _nodeOwner) external; + function activateAttester(address _nodeOwner) external; - function activate_validator(address _nodeOwner) external; + function activateValidator(address _nodeOwner) external; function remove(address _nodeOwner) external;