Skip to content

test_eip_vector_dupn_duplicate_bottom()

Documentation for tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py::test_eip_vector_dupn_duplicate_bottom@a9abd46e.

Generate fixtures for these test cases for Amsterdam with:

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

EIP test vector: 60016000808080808080808080808080808080e680.

Results in 18 stack items, top=1, bottom=1, rest=0.

PUSH1 1, PUSH1 0, 15x DUP1, DUPN[0x80] - After 15 DUP1s: 17 items [0,0,0,...,0,1] - DUPN[0x80]: decode_single(0x80)=17, duplicate position 17 (value 1) - Result: 18 items, top=1, bottom=1

Source code in tests/amsterdam/eip8024_dupn_swapn_exchange/test_eip_vectors.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def test_eip_vector_dupn_duplicate_bottom(
    pre: Alloc,
    state_test: StateTestFiller,
) -> None:
    """
    EIP test vector: 60016000808080808080808080808080808080e680.

    Results in 18 stack items, top=1, bottom=1, rest=0.

    PUSH1 1, PUSH1 0, 15x DUP1, DUPN[0x80]
    - After 15 DUP1s: 17 items [0,0,0,...,0,1]
    - DUPN[0x80]: decode_single(0x80)=17, duplicate position 17 (value 1)
    - Result: 18 items, top=1, bottom=1
    """
    sender = pre.fund_eoa()

    # Build the exact bytecode from the EIP
    code = Op.PUSH1[0x1] + Op.PUSH1[0x0] + Op.DUP1 * 15 + Op.DUPN[17]
    assert bytes(code) == bytes.fromhex(
        "60016000808080808080808080808080808080e680"
    )

    # Verify by storing top and bottom values
    code += Op.PUSH1(0) + Op.SSTORE  # Store top (should be 1) at key 0

    # Pop 16 items to get to bottom 2 items
    code += Op.POP * 16
    # Stack now has 1 item (bottom value = 1)

    # Store bottom value at key 1
    code += Op.PUSH1(1) + Op.SSTORE  # Store bottom (should be 1) at key 1
    code += Op.STOP

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

    post = {
        contract_address: Account(
            storage={
                0: 1,  # top = 1 (from DUPN duplicating position 17)
                1: 1,  # bottom = 1 (original PUSH1 1)
            }
        )
    }

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

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.