Skip to content

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

Description

@spencer-tb

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

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

Safe pattern

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

Already fixed

Still unfixed

EIP-7825 (tests/osaka/eip7825_transaction_gas_limit_cap/test_tx_gas_limit.py)

  • test_tx_gas_limit_cap_contract_creationgas_available // total_cost_floor_per_token
  • test_maximum_gas_refundtx_gas_limit_cap // iteration_cost

EIP-7702 (tests/prague/eip7702_set_code_tx/)

  • test_gas.pymax_gas // Spec.PER_EMPTY_ACCOUNT_COST
  • test_set_code_txs.pygas_for_delegations // Spec.PER_EMPTY_ACCOUNT_COST

Benchmarks (tests/benchmark/)

  • test_transaction_types.pygas_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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-testsArea: Consensus tests.C-refactorCategory: refactorstaleThe Issue/PR has not had any activity for 60 days. PRs will be automatically closed.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions