IConsensusRegistry

Git Source

Author: Matter Labs

Note: security-contact: security@matterlabs.dev

Functions

add

Adds a new validator to the registry.

Fails if validator owner already exists.

Fails if a validator with the same public key already exists.

function add(
  address _validatorOwner,
  bool _validatorIsLeader,
  uint32 _validatorWeight,
  BLS12_381PublicKey calldata _validatorPubKey,
  BLS12_381Signature calldata _validatorPoP
) external;

Parameters

NameTypeDescription
_validatorOwneraddressThe address of the validator's owner.
_validatorIsLeaderboolFlag indicating if the validator is a leader.
_validatorWeightuint32The voting weight of the validator.
_validatorPubKeyBLS12_381PublicKeyThe BLS12-381 public key of the validator.
_validatorPoPBLS12_381SignatureThe proof-of-possession (PoP) of the validator's public key.

remove

Removes a validator from the registry.

Only callable by the contract owner.

Verifies that the validator owner exists in the registry.

function remove(address _validatorOwner) external;

Parameters

NameTypeDescription
_validatorOwneraddressThe address of the owner of the validator to be removed.

changeValidatorActive

Changes the active status of a validator, determining whether it can participate in committees.

Only callable by the contract owner or the validator owner.

Verifies that the validator owner exists in the registry.

function changeValidatorActive(address _validatorOwner, bool _isActive)
  external;

Parameters

NameTypeDescription
_validatorOwneraddressThe address of the owner of the validator whose active status will be changed.
_isActiveboolThe new active status to assign to the validator.

changeValidatorLeader

Changes the validator's leader status in the registry.

Only callable by the contract owner.

Verifies that the validator owner exists in the registry.

function changeValidatorLeader(address _validatorOwner, bool _isLeader)
  external;

Parameters

NameTypeDescription
_validatorOwneraddressThe address of the owner of the validator whose leader status will be changed.
_isLeaderboolThe new leader status to assign to the validator.

changeValidatorWeight

Changes the validator weight of a validator in the registry.

Only callable by the contract owner.

Verifies that the validator owner exists in the registry.

function changeValidatorWeight(address _validatorOwner, uint32 _weight)
  external;

Parameters

NameTypeDescription
_validatorOwneraddressThe address of the owner of the validator whose weight will be changed.
_weightuint32The new validator weight to assign to the validator.

changeValidatorKey

Changes the validator's public key and proof-of-possession in the registry.

Only callable by the contract owner or the validator owner.

Verifies that the validator owner exists in the registry.

function changeValidatorKey(
  address _validatorOwner,
  BLS12_381PublicKey calldata _pubKey,
  BLS12_381Signature calldata _pop
) external;

Parameters

NameTypeDescription
_validatorOwneraddressThe address of the owner of the validator whose key and PoP will be changed.
_pubKeyBLS12_381PublicKeyThe new BLS12-381 public key to assign to the validator.
_popBLS12_381SignatureThe new proof-of-possession (PoP) to assign to the validator.

commitValidatorCommittee

Adds a new commit to the validator committee using the current block number plus delay.

The committee will become active after committeeActivationDelay blocks.

Only callable by the contract owner.

Reverts if validatorsCommitBlock is still in the future.

function commitValidatorCommittee() external;

getValidatorCommittee

Returns an array of ValidatorAttr structs representing the current validator committee and the current leader selection configuration.

Collects active and non-removed validators based on the latest commit to the committee.

function getValidatorCommittee()
  external
  view
  returns (CommitteeValidator[] memory, LeaderSelectionAttr memory);

getNextValidatorCommittee

Returns an array of ValidatorAttr structs representing the pending validator committee and the pending leader selection configuration.

Collects active and non-removed validators that will form the next committee after the current commit becomes active.

Reverts if there is no pending committee (when block.number >= validatorsCommitBlock).

function getNextValidatorCommittee()
  external
  view
  returns (CommitteeValidator[] memory, LeaderSelectionAttr memory);

setCommitteeActivationDelay

Updates the delay for committee activation

Only callable by the contract owner

function setCommitteeActivationDelay(uint256 _delay) external;

Parameters

NameTypeDescription
_delayuint256The new delay in blocks

updateLeaderSelection

Updates the leader selection configuration

Only callable by the contract owner

function updateLeaderSelection(uint64 _frequency, bool _weighted) external;

Parameters

NameTypeDescription
_frequencyuint64The number of views between leader changes. If it is 0 then the leader never rotates.
_weightedboolWhether leaders are selected proportionally to their weight. If false, then the leader is selected round-robin.

Events

ValidatorAdded

event ValidatorAdded(
  address indexed validatorOwner,
  uint32 validatorWeight,
  BLS12_381PublicKey validatorPubKey,
  BLS12_381Signature validatorPoP
);

ValidatorRemoved

event ValidatorRemoved(address indexed validatorOwner);

ValidatorDeleted

event ValidatorDeleted(address indexed validatorOwner);

ValidatorActiveStatusChanged

event ValidatorActiveStatusChanged(
  address indexed validatorOwner, bool isActive
);

ValidatorLeaderStatusChanged

event ValidatorLeaderStatusChanged(
  address indexed validatorOwner, bool isLeader
);

ValidatorWeightChanged

event ValidatorWeightChanged(address indexed validatorOwner, uint32 newWeight);

ValidatorKeyChanged

event ValidatorKeyChanged(
  address indexed validatorOwner,
  BLS12_381PublicKey newPubKey,
  BLS12_381Signature newPoP
);

ValidatorsCommitted

event ValidatorsCommitted(
  uint32 validatorsCommit, uint256 validatorsCommitBlock
);

CommitteeActivationDelayChanged

event CommitteeActivationDelayChanged(uint256 newDelay);

LeaderSelectionChanged

event LeaderSelectionChanged(LeaderSelectionAttr newLeaderSelection);

Errors

UnauthorizedOnlyOwnerOrValidatorOwner

error UnauthorizedOnlyOwnerOrValidatorOwner();

ValidatorOwnerExists

error ValidatorOwnerExists();

ValidatorOwnerDoesNotExist

error ValidatorOwnerDoesNotExist();

ValidatorOwnerNotFound

error ValidatorOwnerNotFound();

ValidatorPubKeyExists

error ValidatorPubKeyExists();

InvalidInputValidatorOwnerAddress

error InvalidInputValidatorOwnerAddress();

InvalidInputBLS12_381PublicKey

error InvalidInputBLS12_381PublicKey();

InvalidInputBLS12_381Signature

error InvalidInputBLS12_381Signature();

NoPendingCommittee

error NoPendingCommittee();

PreviousCommitStillPending

error PreviousCommitStillPending();

NoActiveLeader

error NoActiveLeader();

Structs

Validator

Represents a validator in the consensus protocol.

struct Validator {
  uint32 ownerIdx;
  uint32 lastSnapshotCommit;
  uint32 previousSnapshotCommit;
  ValidatorAttr latest;
  ValidatorAttr snapshot;
  ValidatorAttr previousSnapshot;
}

Properties

NameTypeDescription
ownerIdxuint32Index of the validator owner within the array of validator owners.
lastSnapshotCommituint32The validatorsCommit value when the last snapshot of this validator was made.
previousSnapshotCommituint32The validatorsCommit value when the previous snapshot of this validator was made.
latestValidatorAttrValidator attributes to read if validatorsCommit > validator.lastSnapshotCommit.
snapshotValidatorAttrValidator attributes to read if validatorsCommit > validator.previousSnapshot.
previousSnapshotValidatorAttrValidator attributes to read for older commits.

ValidatorAttr

Represents the attributes of a validator.

struct ValidatorAttr {
  bool active;
  bool removed;
  bool leader;
  uint32 weight;
  BLS12_381PublicKey pubKey;
  BLS12_381Signature proofOfPossession;
}

Properties

NameTypeDescription
activeboolA flag stating if the validator is active.
removedboolA flag stating if the validator has been removed (and is pending a deletion).
leaderboolA flag stating if the validator is eligible to be a leader.
weightuint32Validator's voting weight.
pubKeyBLS12_381PublicKeyValidator's BLS12-381 public key.
proofOfPossessionBLS12_381SignatureValidator's Proof-of-possession (a signature over the public key).

LeaderSelection

Represents the leader selection process in the consensus protocol.

struct LeaderSelection {
  uint32 lastSnapshotCommit;
  uint32 previousSnapshotCommit;
  LeaderSelectionAttr latest;
  LeaderSelectionAttr snapshot;
  LeaderSelectionAttr previousSnapshot;
}

Properties

NameTypeDescription
lastSnapshotCommituint32The validatorsCommit value when the last snapshot was made.
previousSnapshotCommituint32The validatorsCommit value when the previous snapshot was made.
latestLeaderSelectionAttrLeaderSelectionAttr to read if validatorsCommit > lastSnapshotCommit.
snapshotLeaderSelectionAttrLeaderSelectionAttr to read if validatorsCommit > previousSnapshot.
previousSnapshotLeaderSelectionAttrLeaderSelectionAttr to read for older commits.

LeaderSelectionAttr

Attributes for the validator leader selection process.

struct LeaderSelectionAttr {
  uint64 frequency;
  bool weighted;
}

Properties

NameTypeDescription
frequencyuint64The number of views between leader changes. If it is 0 then the leader never rotates.
weightedboolWhether leaders are selectedproportionally to their weight. If false, then the leader is selected round-robin.

CommitteeValidator

Represents a validator within a committee.

struct CommitteeValidator {
  bool leader;
  uint32 weight;
  BLS12_381PublicKey pubKey;
  BLS12_381Signature proofOfPossession;
}

Properties

NameTypeDescription
leaderboolA flag stating if the validator is eligible to be a leader.
weightuint32Validator's voting weight.
pubKeyBLS12_381PublicKeyValidator's BLS12-381 public key.
proofOfPossessionBLS12_381SignatureValidator's Proof-of-possession (a signature over the public key).

BLS12_381PublicKey

Represents BLS12_381 public key.

struct BLS12_381PublicKey {
  bytes32 a;
  bytes32 b;
  bytes32 c;
}

Properties

NameTypeDescription
abytes32First component of the BLS12-381 public key.
bbytes32Second component of the BLS12-381 public key.
cbytes32Third component of the BLS12-381 public key.

BLS12_381Signature

Represents BLS12_381 signature.

struct BLS12_381Signature {
  bytes32 a;
  bytes16 b;
}

Properties

NameTypeDescription
abytes32First component of the BLS12-381 signature.
bbytes16Second component of the BLS12-381 signature.