Skip to content

test_calldata_floor()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py::test_calldata_floor@5c024cbb.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py::test_calldata_floor --fork Amsterdam

A data-heavy transaction to an existing EOA whose calldata floor exceeds the decomposed value-transfer intrinsic.

  • floor_binds: with a gas limit above the floor, gas_used pins to the floor, so the value-transfer charges (TRANSFER_LOG_COST + TX_VALUE_COST) folded into the intrinsic are masked -- the gas paid is identical at value == 0 and value == 1 and only the moved wei differs.
  • below_floor: a gas limit one short of the floor still covers the (smaller) decomposed intrinsic, so the floor -- built on the EIP-2780-lowered TX_BASE -- is the only thing that can reject it, with INTRINSIC_GAS_BELOW_FLOOR_GAS_COST.
Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_calldata_floor.py
 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
@pytest.mark.parametrize(
    "outcome",
    [
        pytest.param("floor_binds", id="floor_binds"),
        pytest.param(
            "below_floor",
            id="below_floor_rejected",
            marks=pytest.mark.exception_test,
        ),
    ],
)
@pytest.mark.parametrize(
    "value",
    [
        pytest.param(0, id="zero_value"),
        pytest.param(1, id="non-zero_value"),
    ],
)
def test_calldata_floor(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
    outcome: str,
    value: int,
) -> None:
    """
    A data-heavy transaction to an existing EOA whose calldata floor
    exceeds the decomposed value-transfer intrinsic.

    - ``floor_binds``: with a gas limit above the floor, ``gas_used``
      pins to the floor, so the value-transfer charges
      (``TRANSFER_LOG_COST + TX_VALUE_COST``) folded into the intrinsic
      are masked -- the gas paid is identical at ``value == 0`` and
      ``value == 1`` and only the moved wei differs.
    - ``below_floor``: a gas limit one short of the floor still covers
      the (smaller) decomposed intrinsic, so the floor -- built on the
      EIP-2780-lowered ``TX_BASE`` -- is the only thing that can reject
      it, with ``INTRINSIC_GAS_BELOW_FLOOR_GAS_COST``.
    """
    sender_initial_balance = 10**18
    sender = pre.fund_eoa(sender_initial_balance)
    target = pre.fund_eoa(amount=EOA_INITIAL_BALANCE)

    calldata = _floor_dominating_calldata(fork)
    calldata_floor = fork.transaction_data_floor_cost_calculator()(
        data=calldata,
        sends_value=bool(value),
        recipient_type=RecipientType.EOA,
    )
    gas_price = 1_000_000_000

    post: dict[Address, Account] = {}
    if outcome == "below_floor":
        # ``gas_limit`` one short of the floor still covers the
        # decomposed intrinsic, so the floor is the only thing that can
        # reject it; the post state is empty (transaction rejected).
        intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
            calldata=calldata,
            sends_value=bool(value),
            recipient_type=RecipientType.EOA,
            return_cost_deducted_prior_execution=True,
        )
        gas_limit = calldata_floor - 1
        assert intrinsic_gas <= gas_limit, (
            "gas_limit must still cover the decomposed intrinsic so the "
            "rejection is pinned to the calldata floor"
        )
        tx = Transaction(
            sender=sender,
            to=target,
            value=value,
            data=calldata,
            gas_limit=gas_limit,
            gas_price=gas_price,
            error=TransactionException.INTRINSIC_GAS_BELOW_FLOOR_GAS_COST,
        )
    else:
        # ``floor_binds``: no explicit gas limit (auto-fills above the
        # floor). The gas component is the floor regardless of value
        # (charges masked); only the transferred wei changes the
        # balance.
        tx = Transaction(
            sender=sender,
            to=target,
            value=value,
            data=calldata,
            gas_price=gas_price,
        )
        sender_final_balance = (
            sender_initial_balance - value - calldata_floor * gas_price
        )
        post = {
            sender: Account(nonce=1, balance=sender_final_balance),
            target: Account(balance=EOA_INITIAL_BALANCE + value),
        }

    state_test(pre=pre, tx=tx, post=post)

Parametrized Test Cases

This test generates 4 parametrized test cases across 1 fork.