Skip to content
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

feat(registry): cheaper on-chain batch opt-in (48k gas) #336

Merged
merged 12 commits into from
Oct 30, 2024

Conversation

merklefruit
Copy link
Collaborator

@merklefruit merklefruit commented Oct 28, 2024

Overview

This PR introduces a slightly more optimized version of BoltValidators that uses an internal library ValidatorsLib.

The main gain in efficiency is due to the new _Validator struct that tightly packs necessary info in a single slot, containing pointers to other mappings, offloading the majority of storage costs when batch registering.

The optimizations performed are geared toward storage costs rather than runtime costs.
In particular the loops, variables, event emission, and other runtime checks haven't been optimized/removed.

Gas usage

We benchmarked BoltValidatorsV2 (new implementation) vs BoltValidatorsV1 (old implementation).

  • previous version: ~120k gas x validator (when batching). Max 250 per block gas limit.
  • new version: ~48k gas x validator (when batching). Max 620 per block gas limit

The image below shows the efficiency curve of batch registration costs:

Gas Cost vs Amount of Validators (Log-Log Scale)

Meta

@merklefruit merklefruit marked this pull request as ready for review October 29, 2024 10:57
@merklefruit merklefruit self-assigned this Oct 29, 2024
@merklefruit merklefruit added C: smart-contracts Component: smart contracts T: feature Type: Feature labels Oct 29, 2024
@merklefruit merklefruit changed the title wip(registry): new storage layout with indexes feat(registry): new storage layout with indexes Oct 29, 2024
@merklefruit merklefruit changed the title feat(registry): new storage layout with indexes feat(registry): cheaper on-chain batch opt-in (48k gas) Oct 29, 2024
Copy link
Contributor

@thedevbirb thedevbirb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First review, will continue tmr!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commenting it here but applies a bit everywhere: wdyt of having a type CompressedHash (or similar name) alias to bytes20? I found it really counter-intuitive to read bytes20 pubkeyHash etc

error OperatorAlreadyRegistered();
error OperatorNotRegistered();
error UnauthorizedMiddleware();
error InactiveOperator();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By grepping over the codebase I've seen InactiveOperator is unused.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn missed this - added a TODO comment

@mempirate mempirate merged commit 795746d into lore/feat/holesky-launch Oct 30, 2024
4 checks passed
@mempirate mempirate deleted the nico/feat/cheaper-unsafe-optin branch October 30, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: smart-contracts Component: smart contracts T: feature Type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants