Skip to content

test_eip_vector_exchange_with_iszero()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_exchange_with_iszero@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_exchange_with_iszero --fork Amsterdam

EIP test vector: 60008080e88e15.

Results in 3 stack items, top=1, rest=0.

PUSH1 0, DUP1, DUP1, EXCHANGE[0x8e], ISZERO - After DUP1s: [0, 0, 0] - EXCHANGE[0x8e]: decode_pair(0x8e)=(1,2), swap pos 2 and 3 - ISZERO: pop 0, push 1 - Result: [1, 0, 0]

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
def test_eip_vector_exchange_with_iszero(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 60008080e88e15.

    Results in 3 stack items, top=1, rest=0.

    PUSH1 0, DUP1, DUP1, EXCHANGE[0x8e], ISZERO
    - After DUP1s: [0, 0, 0]
    - EXCHANGE[0x8e]: decode_pair(0x8e)=(1,2), swap pos 2 and 3
    - ISZERO: pop 0, push 1
    - Result: [1, 0, 0]
    """
    sender = pre.fund_eoa()

    # Build the exact bytecode from the EIP
    code = Op.PUSH1[0x0] + Op.DUP1 + Op.DUP1 + Op.EXCHANGE[b"\x8e"] + Op.ISZERO
    assert bytes(code) == bytes.fromhex("60008080e88e15")

    # Store all 3 stack values
    code += Op.PUSH1(0) + Op.SSTORE  # Store top (should be 1)
    code += Op.PUSH1(1) + Op.SSTORE  # Store position 2 (should be 0)
    code += Op.PUSH1(2) + Op.SSTORE  # Store position 3 (should be 0)
    code += Op.STOP

    contract_address = pre.deploy_contract(code=code)
    tx = Transaction(to=contract_address, sender=sender, gas_limit=1_000_000)

    post = {
        contract_address: Account(
            storage={
                0: 1,  # top = 1 (from ISZERO)
                1: 0,  # position 2 = 0
                2: 0,  # bottom = 0
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.