Skip to content

Add additional checks to consensus contracts #382

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

guidanoli
Copy link
Collaborator

This PR adds the following checks to Authority and Quorum:

  • lastProcessedBlockNumber < block.number: validators cannot process blocks in the future
  • lastProcessedBlockNumber % epochLength == (epochLength - 1): validators have to validate blocks until the last block of an epoch
  • there cannot be two accepted claims for the same epoch

The last point is implemented differently for Authority and Quorum:

  • Authority stores the set of epochs for which a claim was accepted.
  • Quorum stores the set of validators that have submitted a claim for a given epoch.

Both contracts use OpenZeppelin's bitmap data structure to store sets.
In Authority, epochs are identified by their number (lastProcessedBlockNumber / epochLength)
In Quorum, validators are identified by their ID.
Because of how OpenZepplein implements bitmaps and how these numbers are close to one another, this saves gas because fewer storage slots have to be read/written.

Other notable things about this PR:

  • We've bumped solc from 0.8.23 to 0.8.29 (to use require(bool, CustomError) syntax)
  • Adds custom errors to IConsensus for each of these checks
  • In the case of Quorum, if a validator submits the same claim twice, it is simply ignored, and no error is reverted (idempotence). This behavior/feature is a consequence of implementation details.
  • Added two new view functions to IQuorum to consult information about validators that have submitted any claim for a particular epoch (basically exposing the newly-added state variables through the interface).
  • Added tests to cover all cases

@guidanoli guidanoli force-pushed the feature/strong-claim-acceptance branch from 9e43c86 to ffc9348 Compare April 12, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant