Skip to content

test_maximum_calldata_size()

Documentation for tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py::TestMaximumCalldata::test_maximum_calldata_size@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py::TestMaximumCalldata::test_maximum_calldata_size --fork Amsterdam

Test maximum calldata size handling.

Source code in tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
class TestMaximumCalldata:
    """Test maximum calldata size handling."""

    @pytest.fixture
    def sender(self, pre: Alloc) -> Address:
        """Create sender account with massive balance."""
        return pre.fund_eoa()

    @pytest.fixture
    def to(self, pre: Alloc) -> Address:
        """Deploy a simple contract."""
        return pre.deploy_contract(Op.STOP)

    def test_maximum_calldata_size(
        self,
        state_test: StateTestFiller,
        pre: Alloc,
        sender: Address,
        to: Address,
        fork: Fork,
    ) -> None:
        """
        Test transaction with large calldata size (~10M gas worth).

        This verifies that floor cost calculation doesn't overflow and
        gas metering is accurate at scale.
        """
        # Calculate calldata size that would cost approximately 10M gas
        # (below the default block gas limit to avoid EIP-7825 cap issues)
        # Using all non-zero bytes for maximum density
        # floor_cost = TX_BASE + (TX_DATA_TOKEN_FLOOR * tokens)
        # For non-zero bytes: tokens = bytes * 4
        gas_costs = fork.gas_costs()
        target_gas = 10_000_000
        floor_token_cost = gas_costs.TX_DATA_TOKEN_FLOOR
        target_tokens = (target_gas - gas_costs.TX_BASE) // floor_token_cost
        # Use all non-zero bytes for maximum token density
        num_bytes = target_tokens // 4

        calldata = Bytes(b"\x01" * num_bytes)

        # Calculate expected costs
        floor_cost_calculator = fork.transaction_data_floor_cost_calculator()
        floor_cost = floor_cost_calculator(data=calldata)

        intrinsic_cost_calculator = (
            fork.transaction_intrinsic_cost_calculator()
        )
        intrinsic_cost = intrinsic_cost_calculator(
            calldata=calldata,
            contract_creation=False,
            access_list=None,
            authorization_list_or_count=None,
        )

        # Floor cost should dominate for data-heavy transaction
        assert floor_cost > 5_000_000, "Floor cost should be substantial"
        expected_gas = max(intrinsic_cost, floor_cost)

        # Add buffer for execution (cold address access + STOP opcode)
        execution_buffer = 3000
        gas_limit = expected_gas + execution_buffer

        tx = Transaction(
            sender=sender,
            to=to,
            data=calldata,
            gas_limit=gas_limit,
        )

        # Gas used should be the floor cost (execution is minimal)
        tx.expected_receipt = TransactionReceipt(
            cumulative_gas_used=expected_gas
        )

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

test_maximum_calldata_size(state_test, pre, sender, to, fork)

Test transaction with large calldata size (~10M gas worth).

This verifies that floor cost calculation doesn't overflow and gas metering is accurate at scale.

Source code in tests/amsterdam/eip7976_increase_calldata_floor_cost/test_additional_coverage.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
def test_maximum_calldata_size(
    self,
    state_test: StateTestFiller,
    pre: Alloc,
    sender: Address,
    to: Address,
    fork: Fork,
) -> None:
    """
    Test transaction with large calldata size (~10M gas worth).

    This verifies that floor cost calculation doesn't overflow and
    gas metering is accurate at scale.
    """
    # Calculate calldata size that would cost approximately 10M gas
    # (below the default block gas limit to avoid EIP-7825 cap issues)
    # Using all non-zero bytes for maximum density
    # floor_cost = TX_BASE + (TX_DATA_TOKEN_FLOOR * tokens)
    # For non-zero bytes: tokens = bytes * 4
    gas_costs = fork.gas_costs()
    target_gas = 10_000_000
    floor_token_cost = gas_costs.TX_DATA_TOKEN_FLOOR
    target_tokens = (target_gas - gas_costs.TX_BASE) // floor_token_cost
    # Use all non-zero bytes for maximum token density
    num_bytes = target_tokens // 4

    calldata = Bytes(b"\x01" * num_bytes)

    # Calculate expected costs
    floor_cost_calculator = fork.transaction_data_floor_cost_calculator()
    floor_cost = floor_cost_calculator(data=calldata)

    intrinsic_cost_calculator = (
        fork.transaction_intrinsic_cost_calculator()
    )
    intrinsic_cost = intrinsic_cost_calculator(
        calldata=calldata,
        contract_creation=False,
        access_list=None,
        authorization_list_or_count=None,
    )

    # Floor cost should dominate for data-heavy transaction
    assert floor_cost > 5_000_000, "Floor cost should be substantial"
    expected_gas = max(intrinsic_cost, floor_cost)

    # Add buffer for execution (cold address access + STOP opcode)
    execution_buffer = 3000
    gas_limit = expected_gas + execution_buffer

    tx = Transaction(
        sender=sender,
        to=to,
        data=calldata,
        gas_limit=gas_limit,
    )

    # Gas used should be the floor cost (execution is minimal)
    tx.expected_receipt = TransactionReceipt(
        cumulative_gas_used=expected_gas
    )

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.