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

fix(state-transitions): verify deposits against contract #2115

Open
wants to merge 33 commits into
base: main
Choose a base branch
from

Conversation

abi87
Copy link
Collaborator

@abi87 abi87 commented Oct 30, 2024

Deposit list in execution payload body should be validated against the deposit contracts events to avoid creation of fake validators or censorship of real validators.
To do that this PR:

  • Let state-transition processor access the deposit store, similarly to what block builder does
  • Let state-transition processor compare the deposits list from payload with contracts one

Moreover it adds much needed logs to state processor (to be filled in time)

Build on top of #2114

Note:

  • e2e broken with errors like
2024-11-05 19:03:38 2024-11-05T18:03:38Z WARN Failed to get deposits from block(s), retrying... service=deposit num_blocks=["0x5","0xb","0xc"]
2024-11-05 19:03:38 2024-11-05T18:03:38Z ERRR Failed to read deposits service=deposit error=Error -32001 (Receipt not available for From block 5.)
2024-11-05 19:03:38 2024-11-05T18:03:38Z ERRR Failed to read deposits service=deposit error=Error -32001 (Receipt not available for From block 11.)
2024-11-05 19:03:38 2024-11-05T18:03:38Z ERRR Failed to read deposits service=deposit error=Error -32001 (Receipt not available for From block 12.)

and several like

2024-11-05 19:15:34 2024-11-05T18:15:34Z ERRR ‼️ error pruning index ‼️ service=deposit-store-pruner error=DepositKVStore Prune start: 20, end: 16: range start greater than end

@abi87 abi87 self-assigned this Oct 30, 2024
Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@abi87 abi87 changed the base branch from main to state-transition-add-UTs October 30, 2024 18:34
Copy link

codecov bot commented Oct 30, 2024

Codecov Report

Attention: Patch coverage is 55.69620% with 35 lines in your changes missing coverage. Please review.

Project coverage is 26.71%. Comparing base (66bad3e) to head (69d568b).
Report is 17 commits behind head on state-transition-add-UTs.

Files with missing lines Patch % Lines
...ate-transition/pkg/core/state_processor_staking.go 54.76% 15 Missing and 4 partials ⚠️
mod/consensus-types/pkg/types/deposit.go 0.00% 6 Missing ⚠️
beacond/cmd/defaults.go 0.00% 3 Missing ⚠️
mod/beacon/validator/block_builder.go 0.00% 2 Missing ⚠️
mod/node-core/pkg/components/state_processor.go 0.00% 2 Missing ⚠️
...ate-transition/pkg/core/state_processor_genesis.go 89.47% 0 Missing and 2 partials ⚠️
testing/e2e/config/config.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                     Coverage Diff                      @@
##           state-transition-add-UTs    #2115      +/-   ##
============================================================
+ Coverage                     23.48%   26.71%   +3.23%     
============================================================
  Files                           357      357              
  Lines                         16064    16092      +28     
  Branches                         12       12              
============================================================
+ Hits                           3772     4299     +527     
+ Misses                        12121    11519     -602     
- Partials                        171      274     +103     
Files with missing lines Coverage Δ
mod/state-transition/pkg/core/state_processor.go 31.91% <100.00%> (+31.91%) ⬆️
mod/storage/pkg/deposit/store.go 53.84% <100.00%> (+53.84%) ⬆️
testing/e2e/config/config.go 0.00% <0.00%> (ø)
mod/beacon/validator/block_builder.go 0.00% <0.00%> (ø)
mod/node-core/pkg/components/state_processor.go 0.00% <0.00%> (ø)
...ate-transition/pkg/core/state_processor_genesis.go 50.00% <89.47%> (+50.00%) ⬆️
beacond/cmd/defaults.go 0.00% <0.00%> (ø)
mod/consensus-types/pkg/types/deposit.go 86.74% <0.00%> (-6.76%) ⬇️
...ate-transition/pkg/core/state_processor_staking.go 53.19% <54.76%> (+53.19%) ⬆️

... and 7 files with indirect coverage changes

@abi87 abi87 force-pushed the verify-deposits-against-contract branch from d28ec4c to fb9d020 Compare October 30, 2024 18:51
@abi87 abi87 force-pushed the verify-deposits-against-contract branch from fb9d020 to 6a191d1 Compare October 30, 2024 18:52
@@ -87,7 +87,8 @@ func (s *Service[
envelope, err := s.retrieveExecutionPayload(ctx, st, blk)
if err != nil {
return blk, sidecars, err
} else if envelope == nil {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not strictly necessary but OCD kicking in here 😅

@abi87 abi87 marked this pull request as ready for review October 30, 2024 19:00
@abi87 abi87 requested a review from dezzeus October 30, 2024 19:09
@abi87 abi87 force-pushed the verify-deposits-against-contract branch from 9c43988 to 64d19e5 Compare October 30, 2024 19:44
calbera
calbera previously approved these changes Nov 1, 2024
@calbera calbera self-requested a review November 4, 2024 19:55
@calbera calbera dismissed their stale review November 4, 2024 19:55

.Equals func on Deposit

if err != nil {
return err
}
eth1Data, err := st.GetEth1Data()
depositIndex++
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@calbera while adding unit tests spot this bug.
st.GetEth1DepositIndex() store the latest processed deposit, hence we need to move it up to process next.
This is similar to what we do in genesis

Base automatically changed from state-transition-add-UTs to main November 5, 2024 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants