Skip to content

test_top_frame_state_charge_empty_precompile()

Documentation for tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_top_frame_charges.py::test_top_frame_state_charge_empty_precompile@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

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

An empty precompile recipient is still empty per EIP-161, so a value-moving transaction to it must pay the top-frame NEW_ACCOUNT state-gas charge.

The gas limit is one short of covering that state charge. Without the charge, the transaction would reach the identity precompile and transfer value, which makes this a direct regression test for a precompile carve-out.

Source code in tests/amsterdam/eip2780_reduce_intrinsic_tx_gas/test_top_frame_charges.py
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
def test_top_frame_state_charge_empty_precompile(
    fork: Fork,
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    An empty precompile recipient is still empty per EIP-161, so a
    value-moving transaction to it must pay the top-frame
    ``NEW_ACCOUNT`` state-gas charge.

    The gas limit is one short of covering that state charge. Without
    the charge, the transaction would reach the identity precompile and
    transfer value, which makes this a direct regression test for a
    precompile carve-out.
    """
    sender_initial_balance = 10**18
    sender = pre.fund_eoa(sender_initial_balance)
    identity_precompile = Address(0x04)

    value = 1
    intrinsic_gas = fork.transaction_intrinsic_cost_calculator()(
        sends_value=True,
        recipient_type=RecipientType.PRECOMPILE,
        return_cost_deducted_prior_execution=True,
    )
    top_frame_state_gas = fork.transaction_top_frame_state_gas(
        sends_value=True,
        recipient_type=RecipientType.EMPTY_ACCOUNT,
    )
    assert top_frame_state_gas > 0, (
        "top-frame state gas must be non-zero for empty recipients"
    )

    gas_price = 1_000_000_000
    gas_limit = intrinsic_gas + top_frame_state_gas - 1
    tx = Transaction(
        sender=sender,
        to=identity_precompile,
        value=value,
        gas_limit=gas_limit,
        gas_price=gas_price,
    )

    post = {
        sender: Account(
            nonce=1,
            balance=sender_initial_balance - gas_limit * gas_price,
        ),
        identity_precompile: None,
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.