Skip to content

feat(l2): add flag to delay the watcher until a trusted block#2816

Merged
LeanSerra merged 10 commits into
mainfrom
l2/delay_watcher
May 16, 2025
Merged

feat(l2): add flag to delay the watcher until a trusted block#2816
LeanSerra merged 10 commits into
mainfrom
l2/delay_watcher

Conversation

@LeanSerra

Copy link
Copy Markdown
Contributor

Motivation

L1 reorgs can left the L2 in a bad state if a reorged block deposits' are processed.

Description

  • Add the flag watcher_block_delay with default value 0 that represents the amount of blocks of delay the l1 watcher has.
    • If the latest block in l1 is 100 and we set this delay to 10 l1 watcher will look for deposits until block 90
  • Add logs and return empty from the function if
    • We are too close to genesis (current_block - block_delay < 0)
    • We changed the block delay and now the last block verified by the contract is no longer a trusted block

Closes #2187

@LeanSerra LeanSerra self-assigned this May 15, 2025
@LeanSerra LeanSerra added L2 Rollup client sequencer L2 sequencer labels May 15, 2025
@github-actions

github-actions Bot commented May 15, 2025

Copy link
Copy Markdown

Lines of code report

Total lines added: 29
Total lines removed: 0
Total lines changed: 29

Detailed view
+------------------------------------------+-------+------+
| File                                     | Lines | Diff |
+------------------------------------------+-------+------+
| ethrex/cmd/ethrex/l2/options.rs          | 404   | +11  |
+------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/configs.rs    | 53    | +1   |
+------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/l1_watcher.rs | 313   | +17  |
+------------------------------------------+-------+------+

@LeanSerra LeanSerra marked this pull request as ready for review May 15, 2025 20:08
@LeanSerra LeanSerra requested a review from a team as a code owner May 15, 2025 20:08
Comment thread crates/l2/sequencer/l1_watcher.rs Outdated
Comment thread cmd/ethrex/l2/options.rs Outdated
Comment thread crates/l2/sequencer/l1_watcher.rs Outdated
LeanSerra and others added 2 commits May 16, 2025 12:35
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
Comment thread crates/l2/sequencer/l1_watcher.rs Outdated
Comment thread cmd/ethrex/l2/options.rs Outdated
LeanSerra and others added 2 commits May 16, 2025 14:06
Co-authored-by: Manuel Iñaki Bilbao <manuel.bilbao@lambdaclass.com>
Co-authored-by: Manuel Iñaki Bilbao <manuel.bilbao@lambdaclass.com>

@ilitteri ilitteri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Update the watcher_block_delay default value to 2 L1 epochs and override to 0 for the CI run, docker compose, and make init-l2.

Comment thread cmd/ethrex/l2/options.rs Outdated
Comment thread cmd/ethrex/l2/options.rs Outdated
LeanSerra and others added 3 commits May 16, 2025 17:55
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
@LeanSerra LeanSerra enabled auto-merge May 16, 2025 20:56
@LeanSerra LeanSerra added this pull request to the merge queue May 16, 2025
Merged via the queue into main with commit e965019 May 16, 2025
26 checks passed
@LeanSerra LeanSerra deleted the l2/delay_watcher branch May 16, 2025 21:21
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…class#2816)

**Motivation**

L1 reorgs can left the L2 in a bad state if a reorged block deposits'
are processed.

**Description**

- Add the flag `watcher_block_delay` with default value 0 that
represents the amount of blocks of delay the l1 watcher has.
- If the latest block in l1 is 100 and we set this delay to 10 l1
watcher will look for deposits until block 90
- Add logs and return empty from the function if 
   - We are too close to genesis (current_block - block_delay < 0)
- We changed the block delay and now the last block verified by the
contract is no longer a trusted block


Closes lambdaclass#2187

---------

Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
Co-authored-by: Manuel Iñaki Bilbao <manuel.bilbao@lambdaclass.com>
edg-l added a commit that referenced this pull request May 11, 2026
…hannel (bal-devnet-7)

EIPs#11611 / EELS PR #2816 spec the EIP-7702 existing-authority refund
as a dedicated `MessageCallOutput.state_refund` channel: a separate
monotonic accumulator subtracted from `tx_state_gas` at the end of
`process_transaction`. `state_gas_used` and intrinsic state-gas are
explicitly kept immutable after validation so failure-path accounting
(Policy A's `execution_portion` math, regular-gas derivation, etc.)
stays consistent.

ethrex's prior implementation simulated the channel inline by
pre-decrementing both `state_gas_used` and `intrinsic_state_gas_charged`
in `set_delegation`. That worked on success (math nets out at refund_sender)
but corrupted every failure path because Policy A and the block-gas
formula re-derive from the pre-decremented counters — auth refunds
were double-applied, lost, or mis-routed depending on the failure mode.

This commit reifies the spec channel:
- New `VM.state_refund: u64` field (mirrors EELS `state_refund`)
- `set_delegation` (utils.rs:345-367): bumps `state_gas_reservoir` and
  `state_refund`; no longer touches `state_gas_used` or
  `intrinsic_state_gas_charged`
- `refund_sender` (default_hook.rs:254-264): subtracts `vm.state_refund`
  from the state dimension at the end, identically on success and failure

Fixes the 5 state_gas_set_code / intrinsic_gas_cost failures:
- auth_sender_billing_after_failure
- existing_account_auth_header_gas_used_reflects_refund
- existing_auth_refund_survives_top_level_revert
- auth_state_gas_in_header_after_failure
- prague/eip7702_set_code_tx/gas/intrinsic_gas_cost (duplicate-auth case)

`state_refund` lives on the VM, never snapshotted, so it naturally
survives revert/halt/OOG without any call-frame backup machinery.
edg-l added a commit that referenced this pull request May 11, 2026
The zkevm@v0.3.3 fixture bundle (the only bundle that ships
executionWitness, used by test-stateless-zkevm) is filled against an
older bal spec and disagrees with bal@v7.0.0 gas accounting:
storage_set/new_account/cpsb constants pre-recalibration plus pre-
EELS-#2815/#2816/#2823/#2827/#2828 refund-channel semantics.

Skips the 21 remaining gas mismatches in the eip8025_optional_proofs
filter (witness_codes_*, witness_state_*, validation_state_*),
analogous to the bal@v5.6.1 block already at the top of the list.
Re-enable once the zkevm bundle is regenerated against bal-7.
edg-l added a commit that referenced this pull request May 11, 2026
bal-devnet-6 EELS spec (`devnets/bal/6` `eoa_delegation.py`) only does
`message.state_gas_reservoir += STATE_BYTES_PER_NEW_ACCOUNT × cpsb`
on each existing-authority refund. Docstring: "no mutation of
intrinsic_state_gas".

Drops the two extra subtractions previously added in `cefdf69de` that
anticipated EELS PR #2711 / #2816 (the bal-7 `state_refund` channel).
For bal-6 the block-level `state_gas_used` intentionally stays
"inflated" by the auth refund — the refund is sender-side only in this
devnet. Block-accounting subtraction lands in bal-devnet-7 via the
separate `state_refund` channel.

Unblocks the snobal-devnet-6 EIP-7702 fixtures previously allowlisted
under "bal-devnet-6 known-failing fixtures (Amsterdam fork only)" in
tooling/ef_tests/blockchain/tests/all.rs.
edg-l added a commit that referenced this pull request May 13, 2026
…hannel (bal-devnet-7)

EIPs#11611 / EELS PR #2816 spec the EIP-7702 existing-authority refund
as a dedicated `MessageCallOutput.state_refund` channel: a separate
monotonic accumulator subtracted from `tx_state_gas` at the end of
`process_transaction`. `state_gas_used` and intrinsic state-gas are
explicitly kept immutable after validation so failure-path accounting
(Policy A's `execution_portion` math, regular-gas derivation, etc.)
stays consistent.

ethrex's prior implementation simulated the channel inline by
pre-decrementing both `state_gas_used` and `intrinsic_state_gas_charged`
in `set_delegation`. That worked on success (math nets out at refund_sender)
but corrupted every failure path because Policy A and the block-gas
formula re-derive from the pre-decremented counters — auth refunds
were double-applied, lost, or mis-routed depending on the failure mode.

This commit reifies the spec channel:
- New `VM.state_refund: u64` field (mirrors EELS `state_refund`)
- `set_delegation` (utils.rs:345-367): bumps `state_gas_reservoir` and
  `state_refund`; no longer touches `state_gas_used` or
  `intrinsic_state_gas_charged`
- `refund_sender` (default_hook.rs:254-264): subtracts `vm.state_refund`
  from the state dimension at the end, identically on success and failure

Fixes the 5 state_gas_set_code / intrinsic_gas_cost failures:
- auth_sender_billing_after_failure
- existing_account_auth_header_gas_used_reflects_refund
- existing_auth_refund_survives_top_level_revert
- auth_state_gas_in_header_after_failure
- prague/eip7702_set_code_tx/gas/intrinsic_gas_cost (duplicate-auth case)

`state_refund` lives on the VM, never snapshotted, so it naturally
survives revert/halt/OOG without any call-frame backup machinery.
edg-l added a commit that referenced this pull request May 13, 2026
The zkevm@v0.3.3 fixture bundle (the only bundle that ships
executionWitness, used by test-stateless-zkevm) is filled against an
older bal spec and disagrees with bal@v7.0.0 gas accounting:
storage_set/new_account/cpsb constants pre-recalibration plus pre-
EELS-#2815/#2816/#2823/#2827/#2828 refund-channel semantics.

Skips the 21 remaining gas mismatches in the eip8025_optional_proofs
filter (witness_codes_*, witness_state_*, validation_state_*),
analogous to the bal@v5.6.1 block already at the top of the list.
Re-enable once the zkevm bundle is regenerated against bal-7.
edg-l added a commit that referenced this pull request May 13, 2026
…hannel (bal-devnet-7)

EIPs#11611 / EELS PR #2816 spec the EIP-7702 existing-authority refund
as a dedicated `MessageCallOutput.state_refund` channel: a separate
monotonic accumulator subtracted from `tx_state_gas` at the end of
`process_transaction`. `state_gas_used` and intrinsic state-gas are
explicitly kept immutable after validation so failure-path accounting
(Policy A's `execution_portion` math, regular-gas derivation, etc.)
stays consistent.

ethrex's prior implementation simulated the channel inline by
pre-decrementing both `state_gas_used` and `intrinsic_state_gas_charged`
in `set_delegation`. That worked on success (math nets out at refund_sender)
but corrupted every failure path because Policy A and the block-gas
formula re-derive from the pre-decremented counters — auth refunds
were double-applied, lost, or mis-routed depending on the failure mode.

This commit reifies the spec channel:
- New `VM.state_refund: u64` field (mirrors EELS `state_refund`)
- `set_delegation` (utils.rs:345-367): bumps `state_gas_reservoir` and
  `state_refund`; no longer touches `state_gas_used` or
  `intrinsic_state_gas_charged`
- `refund_sender` (default_hook.rs:254-264): subtracts `vm.state_refund`
  from the state dimension at the end, identically on success and failure

Fixes the 5 state_gas_set_code / intrinsic_gas_cost failures:
- auth_sender_billing_after_failure
- existing_account_auth_header_gas_used_reflects_refund
- existing_auth_refund_survives_top_level_revert
- auth_state_gas_in_header_after_failure
- prague/eip7702_set_code_tx/gas/intrinsic_gas_cost (duplicate-auth case)

`state_refund` lives on the VM, never snapshotted, so it naturally
survives revert/halt/OOG without any call-frame backup machinery.
edg-l added a commit that referenced this pull request May 13, 2026
The zkevm@v0.3.3 fixture bundle (the only bundle that ships
executionWitness, used by test-stateless-zkevm) is filled against an
older bal spec and disagrees with bal@v7.0.0 gas accounting:
storage_set/new_account/cpsb constants pre-recalibration plus pre-
EELS-#2815/#2816/#2823/#2827/#2828 refund-channel semantics.

Skips the 21 remaining gas mismatches in the eip8025_optional_proofs
filter (witness_codes_*, witness_state_*, validation_state_*),
analogous to the bal@v5.6.1 block already at the top of the list.
Re-enable once the zkevm bundle is regenerated against bal-7.
akshay-ap pushed a commit to akshay-ap/ethrex that referenced this pull request May 19, 2026
**Motivation**

Bring ethrex up to bal-devnet-7 (BAL fixtures `bal@v7.1.1`). Stacked
on top of #bal-devnet-6-pr (now in main).

**Description**

Aligns EIP-8037 state-gas accounting with bal-devnet-7 spec progression
(EELS PRs lambdaclass#2815 / lambdaclass#2816 / lambdaclass#2823 / lambdaclass#2827 / lambdaclass#2828 / lambdaclass#2836 / lambdaclass#2845 /
lambdaclass#2848),
bumps Amsterdam fixtures from `snobal-devnet-6@v1.1.0` to `bal@v7.1.1`,
and bumps the pinned hive version past the ethrex `--http.api` fix.

Main changes:

- EIP-8037 state-gas alignment with bal-devnet-7:
  - System-call state-gas reservoir.
  - Halt refunds spilled state gas (Policy A).
  - Tx-level CREATE failure refunds intrinsic `NEW_ACCOUNT`;
    `intrinsic_state_gas_charged` preserved across the failure path.
  - Tx-CREATE collision refund with regular-gas burn; billing matches
    EELS.
  - Cross-frame revert leaks inline credits.
  - Cross-frame revert reservoir formula fix.
  - Block-level `state_gas_used` subtracts `state_refund`.
- Remove same-tx SELFDESTRUCT state-gas refund (EELS PR lambdaclass#2845, v7.1.0).
- EIP-7702:
  - `set_delegation` refund via dedicated `state_refund` channel.
  - `set_delegation` refunds `AUTH_BASE` on existing delegation
    (EELS PR lambdaclass#2836).
  - `set_delegation` refunds `AUTH_BASE` on delegation clear
    (EELS PR lambdaclass#2848, v7.1.1).
- levm fixes pulled from main:
  - `revert` doesn't unmark the account as existing (lambdaclass#6592).
  - Account erroneously considered as existing after zero-value transfer
    (lambdaclass#6591).
- Tooling / tests:
  - Per-tx gas-dimension dump on block `gas_used` mismatch.
  - Bump Amsterdam fixtures to `bal@v7.1.1`.
  - Annotate BAL balance-mismatch errors with gas-equivalent diff and
    recognised state-gas constant multiples.
  - Unskip 74 bal-devnet-6 Amsterdam fixtures now passing.
  - Skip 21 stale EIP-8025 fixtures pinned at `bal@v5.7.0`
    (zkevm@v0.3.3 bundle, pre-bal-7).
  - Drop stale bal-devnet-6 known-issues entries from
    `docs/known_issues.md` and hive `KNOWN_EXCLUDED_TESTS`.
- CI:
  - Bump pinned hive version past the ethrex `--http.api` flag
    feature-detect fix (`c4d839b3`, hive lambdaclass#1485). Without this, hive
    starts ethrex with the default HTTP namespace allowlist
    (`eth,net,web3`) and tests touching `admin_*`/`debug_*`/`txpool_*`
    fail.

**Local test run**

`./run_test.sh` against `tests-bal@v7.1.1`: 2,145 / 2,145 pass.
`cargo test -p ethrex-test --tests`: 453 / 453 pass.

**Checklist**

- [ ] Updated `STORE_SCHEMA_VERSION` (crates/storage/lib.rs) if the PR
  includes breaking changes to the `Store` requiring a re-sync.

---------

Co-authored-by: Lucas Fiegl <iovoid@users.noreply.github.com>
Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L2 Rollup client sequencer L2 sequencer

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

L2: Consider delaying the watcher to a few blocks back.

5 participants