Skip to content

test(invariants): add TIP-1016 state gas invariant tests and update GasPricing/BlockGasLimits for gas dimension split#3369

Open
fgimenez wants to merge 40 commits intotip1016from
fgimenez/tip1016-invariants
Open

test(invariants): add TIP-1016 state gas invariant tests and update GasPricing/BlockGasLimits for gas dimension split#3369
fgimenez wants to merge 40 commits intotip1016from
fgimenez/tip1016-invariants

Conversation

@fgimenez
Copy link
Copy Markdown
Member

Updates existing invariant tests and adds new ones for TIP-1016's gas dimension split (regular vs state gas).

GasPricing.t.sol: Fixed handler_multipleNewSlots which was broken post-TIP-1016 — only 20k regular gas per SSTORE counts against limits, so the old "gas for 1 slot" threshold no longer caused N>1 to fail. Added state gas tracking ghost variables.

BlockGasLimits.t.sol: Reworked tx gas cap enforcement — tx.gas > cap is now valid when excess is state gas. Updated deployment gas calculation to split regular/state components so tx.gas can exceed the cap for large contracts.

TIP1016.t.sol: New test covering 12 invariants across gas dimension split (GAS1-3), reservoir model (RES1-3), block accounting (BLK1-3), and refund semantics (REF1-2).

rakita and others added 30 commits March 27, 2026 16:40
Bump dependencies to EIP-8037 (State Gas Reservoir Model) branches:
- reth: 2a94eed → ff2f857e (eip8037 branch)
- revm: patched via local path at 3a29466d (rakita/state-gas branch)
- alloy-evm: patched to a8da352a (eip8037 branch)
- revm-inspectors: patched to 50676ae7 (eip8037 branch)

Adapt to API changes: PrecompileOutput now uses GasTracker instead of
gas_used/gas_refunded fields, PrecompileResult error type changed to
PrecompileFailure, InitialAndFloorGas.initial_gas renamed to
initial_total_gas, Handler trait methods gained EIP-8037 parameters,
ResultGas removed with_limit(), and commit_transaction returns GasOutput.
Let `?` auto-convert via `From<PrecompileError> for PrecompileFailure`
instead of wrapping explicitly with `PrecompileFailure::from(...)`.
Remove serde-bincode-compat features and RlpBincode impls removed
upstream, drop redundant SignedTransaction/InMemorySize impls now
covered by blanket impls, and migrate spent() to total_gas_spent()
for EIP-8037.
Bump dependencies to EIP-8037 (State Gas Reservoir Model) branches:
- reth: 2a94eed → ff2f857e (eip8037 branch)
- revm: patched via local path at 3a29466d (rakita/state-gas branch)
- alloy-evm: patched to a8da352a (eip8037 branch)
- revm-inspectors: patched to 50676ae7 (eip8037 branch)

Adapt to API changes: PrecompileOutput now uses GasTracker instead of
gas_used/gas_refunded fields, PrecompileResult error type changed to
PrecompileFailure, InitialAndFloorGas.initial_gas renamed to
initial_total_gas, Handler trait methods gained EIP-8037 parameters,
ResultGas removed with_limit(), and commit_transaction returns GasOutput.
Bump dependencies to EIP-8037 (State Gas Reservoir Model) branches:
- reth: 2a94eed → ff2f857e (eip8037 branch)
- revm: patched via local path at 3a29466d (rakita/state-gas branch)
- alloy-evm: patched to a8da352a (eip8037 branch)
- revm-inspectors: patched to 50676ae7 (eip8037 branch)

Adapt to API changes: PrecompileOutput now uses GasTracker instead of
gas_used/gas_refunded fields, PrecompileResult error type changed to
PrecompileFailure, InitialAndFloorGas.initial_gas renamed to
initial_total_gas, Handler trait methods gained EIP-8037 parameters,
ResultGas removed with_limit(), and commit_transaction returns GasOutput.
…(TIP-1016) (#2734)

Closes CHAIN-791

Adds block-level plumbing to track execution gas and storage creation
gas separately in `TempoBlockExecutor`.

- Added `cumulative_full_gas_used` and `cumulative_storage_creation_gas`
fields to `TempoBlockExecutor`
- `commit_transaction` now computes `execution_gas = full_gas -
storage_creation_gas` and only execution gas counts toward block gas
limits (`non_shared_gas_left`, `non_payment_gas_left`)
- Receipts and `cumulative_full_gas_used` continue to track full gas
(execution + storage creation)
- `finish()` returns execution gas (not full gas) for the block header
gas field
- `storage_creation_gas` is hardcoded to `0` with a TODO — it will be
populated once handler-level tracking lands (CHAIN-789 / PR #2714)

Note: hardfork gating is not required. With `storage_creation_gas = 0`,
all gas accounting is identical to the current behavior. The hardfork
gate (T2) lives in the handler layer, not here. This is pure plumbing
that becomes active only when upstream EVM tracking is enabled.
… (TIP-1016) (#2714)

Closes CHAIN-789

Introduces state gas tracking in the EVM handler for the T2 hardfork.
State gas separates the cost of state-touching operations (account
creation, contract deployment) from execution gas, enabling the
reservoir model and tx cap bypass for state-heavy transactions.

`crates/evm/src/lib.rs`:
- Set `cfg_env.enable_state_gas = spec.is_t2()` in both `evm_env` and
`next_evm_env`

`crates/revm/src/handler.rs`
- `adjusted_initial_gas`: propagate `initial_state_gas` through
`InitialAndFloorGas::new_with_state_gas`
- `calculate_aa_batch_intrinsic_gas`: track `new_account_state_gas +
create_state_gas` for AA CREATE calls
- Multi-call gas reconstruction: use flattened `Gas::new_spent` +
`erase_cost` pattern (robust under EIP-8037 reservoir model) and
accumulate `state_gas_spent` across calls
- Tx gas limit cap bypass: upstream revm already skips the cap check
when `enable_state_gas` is true
- `reimburse_caller`: no changes needed — `gas.used()` already includes
state gas through the reservoir flattening in `last_frame_result`
Co-authored-by: rakita <rakita@users.noreply.github.com>
…or of inner executor's block_regular_gas_used
fgimenez and others added 9 commits March 27, 2026 17:29
…erflow in revm's execution/first_frame_input subtraction
…bc7, reth to b25459035f

- reth-primitives-traits and reth-codecs now from crates.io (extracted from reth repo)
- Remove TempoPayloadBuilderAttributes (PayloadBuilderAttributes trait removed upstream)
- Add payload_id() to TempoPayloadAttributes PayloadAttributes impl
- Update BuildArguments::new(), builder.finish(), EthBuiltPayload::new() signatures
- Add into_result() to TxResult impl, rename tx_gas_used -> cumulative_tx_gas_used
- Remove EngineApiMessageVersion from fork_choice_updated() calls
- Update Decompress impl to use reth_codecs::DecompressError
- Rename tx_gas_used -> cumulative_tx_gas_used in test
- Add missing gas_used arg to into_precompile_result
- Remove EngineApiMessageVersion from fork_choice_updated calls in tests
- Remove unused PayloadId import
@fgimenez fgimenez added C-test A change that impacts how or what we test A-precompile Related to precompiles labels Mar 30, 2026
…asPricing/BlockGasLimits for gas dimension split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-precompile Related to precompiles C-test A change that impacts how or what we test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants