ethereum / ethereum/execution-specs

refactor(tests): replace manual intrinsic gas arithmetic broken by EIP-7976/EIP-7981 repricing

Open
#2,289 2 comments 0 reactions 0 assignees View on GitHub
A-tests C-refactor stale
Dominant language
Python
Stars
1.2k
Forks
505
Avg merge
2d 14h
Merged PRs (30d)
116

Description

## Description

Several tests manually compute gas budgets by dividing available gas by raw constants from `fork.gas_costs()` (e.g. `G_ACCESS_LIST_ADDRESS`, `G_TX_DATA_FLOOR_TOKEN_COST`, `PER_EMPTY_ACCOUNT_COST`). This pattern breaks when a new fork reprices these costs, which is what happens in Amsterdam with EIP-7976 (calldata repricing) and EIP-7981 (access list repricing).

Related to #2049 (migration from `fork.gas_costs` to `bytecode.gas_cost(fork)`), that issue covers opcode-level gas costs, while this tracks intrinsic transaction gas calculations that should use the fork's `intrinsic_cost()` calculator via binary search instead of manual division.

## Anti-pattern

```python
gas_available = some_limit - intrinsic_cost()
count = gas_available // SOME_GAS_CONSTANT
```

## Safe pattern

```python
count = max_count_with_intrinsic_cost_at_most(
lambda n: intrinsic_cost(..., n),
some_limit,
)
```

## Already fixed

- `test_tx_gas_limit_cap_access_list_with_diff_keys` (#2250)
- `test_tx_gas_limit_cap_access_list_with_diff_addr` (#2250)
- `test_tx_gas_limit_cap_authorized_tx` (#2250)
- `test_tx_gas_limit_cap_full_calldata` (#2250, #2286)
- `_exact_size_transactions_impl` in EIP-7934 tests (#2252)
- `test_refunds` in EIP-7623 tests (#2252)

## Still unfixed

### EIP-7825 (`tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py`)
- `test_tx_gas_limit_cap_contract_creation` — `gas_available // total_cost_floor_per_token`
- `test_maximum_gas_refund` — `tx_gas_limit_cap // iteration_cost`

### EIP-7702 (`tests/prague/eip7702_set_code_tx/`)
- `test_gas.py` — `max_gas // Spec.PER_EMPTY_ACCOUNT_COST`
- `test_set_code_txs.py` — `gas_for_delegations // Spec.PER_EMPTY_ACCOUNT_COST`

### Benchmarks (`tests/benchmark/`)
- `test_transaction_types.py` — `gas_amount // total_cost_floor_per_token`, `gas_after_address // gas_per_storage_key`
- `test_system.py` — `(per_tx_gas - intrinsic_cost) // (access_list_addr_cost + cost)`

Contributor guide

Open the contributing guide

Research direction

Start with the listed tests in tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py, tests/prague/eip7702_set_code_tx/test_gas.py, tests/prague/eip7702_set_code_tx/test_set_code_txs.py, and the benchmark files. Replace each manual gas-constant division with max_count_with_intrinsic_cost_at_most and the relevant intrinsic_cost calculation, then verify the affected tests and benchmarks no longer depend on repriced raw constants.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
performance, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.