Skip to content

test_pricing_at_various_gas_limits()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_pricing_at_various_gas_limits@636b5f17.

Generate fixtures for these test cases for Bogota with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py::test_pricing_at_various_gas_limits --fork Bogota

Test SSTORE succeeds at various block gas limits.

EIP-8037 prices state gas at a constant cost_per_state_byte, independent of block gas limit. At each block size, an SSTORE zero-to-nonzero should succeed when given sufficient total gas.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_pricing.py
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@EIPChecklist.GasCostChanges.Test.GasUpdatesMeasurement()
@pytest.mark.parametrize("block_gas_limit", BLOCK_GAS_LIMITS)
@pytest.mark.valid_from("EIP8037")
def test_pricing_at_various_gas_limits(
    state_test: StateTestFiller,
    pre: Alloc,
    block_gas_limit: int,
    fork: Fork,
) -> None:
    """
    Test SSTORE succeeds at various block gas limits.

    EIP-8037 prices state gas at a constant `cost_per_state_byte`,
    independent of block gas limit. At each block size, an SSTORE
    zero-to-nonzero should succeed when given sufficient total gas.
    """
    storage = Storage()
    code = Op.SSTORE(
        storage.store_next(1),
        1,
        # gas accounting
        original_value=0,
        new_value=1,
    )
    env = Environment(gas_limit=block_gas_limit)

    gas_limit = (
        fork.transaction_intrinsic_cost_calculator()()
        + fork.transaction_top_frame_execution_gas()
        + code.gas_cost(fork)
    )

    tx_gas = min(gas_limit, block_gas_limit)

    contract = pre.deploy_contract(
        code=code,
    )

    # The state charge does not scale with the block gas limit, so the
    # header reports the same `gas_used` at 1M and at 1G.
    state_gas = code.state_cost(fork)
    execution_gas = gas_limit - state_gas
    expected_gas_used = max(execution_gas, state_gas)
    assert expected_gas_used == state_gas, (
        "expected state gas to dominate execution gas"
    )

    tx = Transaction(
        to=contract,
        gas_limit=tx_gas,
        sender=pre.fund_eoa(),
    )

    post = {contract: Account(storage=storage)}
    state_test(
        env=env,
        pre=pre,
        post=post,
        tx=tx,
        blockchain_test_header_verify=Header(gas_used=expected_gas_used),
    )

Parametrized Test Cases

This test generates 10 parametrized test cases across 2 forks.