Skip to content

test_block_gas_used_dimension_switch_at_transition()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py::test_block_gas_used_dimension_switch_at_transition@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py::test_block_gas_used_dimension_switch_at_transition --fork Amsterdam

Test the block header switches to two-dimensional accounting at the fork boundary.

The same storage-creating transaction is mined either side of the boundary. Before the fork the header reports the scalar execution total; after it the header reports max(execution, state), which the state charge dominates. Only a header assertion separates the two — the post-state is identical.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_fork_transition.py
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 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
121
122
@EIPChecklist.GasCostChanges.Test.ForkTransition.Before()
@EIPChecklist.GasCostChanges.Test.ForkTransition.After()
def test_block_gas_used_dimension_switch_at_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    fork: Fork,
) -> None:
    """
    Test the block header switches to two-dimensional accounting at the
    fork boundary.

    The same storage-creating transaction is mined either side of the
    boundary. Before the fork the header reports the scalar execution
    total; after it the header reports `max(execution, state)`, which the
    state charge dominates. Only a header assertion separates the two —
    the post-state is identical.
    """
    before_fork = fork.fork_at(timestamp=14_999)
    after_fork = fork.fork_at(timestamp=15_000)

    code = Op.SSTORE(0, 1, original_value=0, new_value=1)
    state_gas = code.state_cost(after_fork)
    assert code.state_cost(before_fork) == 0, "no state dimension yet"

    before_gas_used = (
        before_fork.transaction_intrinsic_cost_calculator()()
        + code.gas_cost(before_fork)
    )
    after_execution = (
        after_fork.transaction_intrinsic_cost_calculator()()
        + code.execution_cost(after_fork)
    )
    assert state_gas > after_execution, (
        "the state dimension must set the post-fork header"
    )

    storage_before = Storage()
    writer_before = pre.deploy_contract(
        code=Op.SSTORE(storage_before.store_next(1), 1)
    )
    storage_after = Storage()
    writer_after = pre.deploy_contract(
        code=Op.SSTORE(storage_after.store_next(1), 1)
    )

    blockchain_test(
        pre=pre,
        blocks=[
            Block(
                timestamp=14_999,
                txs=[
                    Transaction(
                        to=writer_before,
                        state_gas_reservoir=0,
                        sender=pre.fund_eoa(),
                    )
                ],
                header_verify=Header(gas_used=before_gas_used),
            ),
            Block(
                timestamp=15_000,
                txs=[
                    Transaction(
                        to=writer_after,
                        state_gas_reservoir=0,
                        sender=pre.fund_eoa(),
                    )
                ],
                header_verify=Header(gas_used=state_gas),
            ),
        ],
        post={
            writer_before: Account(storage=storage_before),
            writer_after: Account(storage=storage_after),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.