Skip to content

test_calldata_floor_with_sstore()

Documentation for tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py::test_calldata_floor_with_sstore@622620d8.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py::test_calldata_floor_with_sstore --fork Amsterdam

Test calldata floor does not affect state gas charging.

The calldata is sized to the exact length at which the floor overtakes the SSTORE's state gas, so the two variants sit one byte either side of that boundary. The block bills the state charge below it and the floor above it, while the sender's bill stays the sum of both dimensions throughout: the floor never discounts the state gas, and the state gas never discounts the floor.

Source code in tests/amsterdam/eip8037_state_creation_gas_cost_increase/test_state_gas_calldata_floor.py
 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
123
124
125
126
127
128
@EIPChecklist.GasRefundsChanges.Test.CrossFunctional.CalldataCost()
@pytest.mark.parametrize(
    "floor_dominates",
    [
        pytest.param(False, id="state_gas_dominates"),
        pytest.param(True, id="calldata_floor_dominates"),
    ],
)
@pytest.mark.valid_from("EIP8037")
def test_calldata_floor_with_sstore(
    state_test: StateTestFiller,
    pre: Alloc,
    fork: Fork,
    floor_dominates: bool,
) -> None:
    """
    Test calldata floor does not affect state gas charging.

    The calldata is sized to the exact length at which the floor
    overtakes the SSTORE's state gas, so the two variants sit one byte
    either side of that boundary. The block bills the state charge
    below it and the floor above it, while the sender's bill stays the
    sum of both dimensions throughout: the floor never discounts the
    state gas, and the state gas never discounts the floor.
    """
    storage = Storage()
    code = Op.SSTORE(storage.store_next(1), 1, new_value=1)
    state_cost = code.state_cost(fork)
    execution_cost = code.execution_cost(fork)

    flip_length = calldata_length_where_floor_overtakes(fork, state_cost)
    calldata = b"\x01" * (flip_length if floor_dominates else flip_length - 1)

    floor = fork.transaction_data_floor_cost_calculator()(data=calldata)
    intrinsic = fork.transaction_intrinsic_cost_calculator()(
        calldata=calldata,
        return_cost_deducted_prior_execution=True,
    )
    tx_execution = intrinsic + execution_cost
    assert tx_execution < state_cost, (
        "the code's own execution gas must stay under the state gas, so "
        "the floor alone decides the execution dimension"
    )
    if floor_dominates:
        assert floor > state_cost, "calldata floor must outgrow the state gas"
    else:
        assert floor < state_cost, (
            "calldata floor must stay under the state gas"
        )

    contract = pre.deploy_contract(code=code)

    tx = Transaction(
        to=contract,
        data=calldata,
        state_gas_reservoir=0,
        sender=pre.fund_eoa(),
        expected_receipt=TransactionReceipt(
            cumulative_gas_used=tx_execution + state_cost
        ),
    )

    state_test(
        pre=pre,
        post={contract: Account(storage=storage)},
        tx=tx,
        blockchain_test_header_verify=Header(
            gas_used=max(tx_execution, floor, state_cost)
        ),
    )

Parametrized Test Cases

This test generates 2 parametrized test cases across 1 fork.