Skip to content

fix(l1): add deposit request layout validations + return invalid deposit request error #2832

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

Merged
merged 8 commits into from
May 19, 2025

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented May 16, 2025

Motivation
Currently, when we fail to parse a deposit request we simply ignore it and keep the rest of the deposits, relying on the request hash check afterwards to notice the missing deposit request. This PR handles the error earlier and returns the appropriate InvalidDepositRequest Error. This will provide better debugging information and also more accurate testing via tools such as execution-spec-tests which rely on specific error returns.
We also were not correctly validating the layout according to the EIP, as we were only checking the total size and not the size and offset of each request field

Description

  • Check that the full layout of deposit requests is valid (aka the internal sizes and offsets of the encoded data)
  • Handle errors when parsing deposit requests
  • Check log topic matches deposit topic before parsing a request as a deposit request

Allows us to address review comment made on execution-specs-test PR ethereum/execution-spec-tests#1607 + also closes #2132

@fmoletta fmoletta marked this pull request as ready for review May 16, 2025 18:43
@fmoletta fmoletta requested a review from a team as a code owner May 16, 2025 18:43
@fmoletta fmoletta marked this pull request as draft May 16, 2025 18:44
Copy link

github-actions bot commented May 16, 2025

Lines of code report

Total lines added: 110
Total lines removed: 10
Total lines changed: 120

Detailed view
+----------------------------------------------------+-------+------+
| File                                               | Lines | Diff |
+----------------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs             | 495   | -10  |
+----------------------------------------------------+-------+------+
| ethrex/crates/blockchain/fork_choice.rs            | 142   | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/common/types/requests.rs             | 206   | +47  |
+----------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection.rs    | 540   | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/engine/fork_choice.rs | 389   | +4   |
+----------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/engine/payload.rs     | 724   | +5   |
+----------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/client.rs         | 31    | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/api.rs                       | 251   | +2   |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs                     | 1225  | +8   |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/in_memory.rs        | 609   | +8   |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/libmdbx.rs          | 1366  | +10  |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/redb.rs             | 1219  | +17  |
+----------------------------------------------------+-------+------+
| ethrex/crates/storage/utils.rs                     | 50    | +2   |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs              | 637   | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/revm/mod.rs              | 639   | +1   |
+----------------------------------------------------+-------+------+
| ethrex/crates/vm/errors.rs                         | 121   | +2   |
+----------------------------------------------------+-------+------+

@fmoletta fmoletta changed the title fix(l1): return error when failing to parse deposit requests fix(l1): add deposit request layout validations + return invalid deposit request error May 16, 2025
@fmoletta fmoletta marked this pull request as ready for review May 19, 2025 17:31
@@ -17,6 +20,11 @@ const DEPOSIT_TYPE: u8 = 0x00;
const WITHDRAWAL_TYPE: u8 = 0x01;
const CONSOLIDATION_TYPE: u8 = 0x02;

lazy_static! {
static ref DEPOSIT_TOPIC: H256 =
H256::from_str("649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c5").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to have these constants in a centralized place like https://github.com/lambdaclass/ethrex/blob/main/crates/common/constants.rs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is something specific to requests so I don't think we will be using it anywhere else to warrant it being centralized

@fmoletta fmoletta added this pull request to the merge queue May 19, 2025
Merged via the queue into main with commit c716b18 May 19, 2025
20 checks passed
@fmoletta fmoletta deleted the invalid-deposit-event-layout branch May 19, 2025 21:21
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.

Fix Sepolia deposit contract issue
3 participants