Skip to content

test_factory_deploys_across_transition()

Documentation for tests/amsterdam/eip7997_deterministic_factory_predeploy/test_fork_transition.py::test_factory_deploys_across_transition@c74f1a67.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7997_deterministic_factory_predeploy/test_fork_transition.py::test_factory_deploys_across_transition --fork Amsterdam

A pre-existing factory keeps deploying contracts across the Amsterdam transition, with its nonce accruing normally.

Asserting that final nonce is what catches the glamsterdam-devnet-6 bug: a client that re-injects EIP-7997 at the transition resets the already-used factory back to nonce 1, diverging the post-state root. Deployment success alone cannot catch it, since the CREATE2 address does not depend on the factory nonce.

Source code in tests/amsterdam/eip7997_deterministic_factory_predeploy/test_fork_transition.py
 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
 72
 73
 74
 75
 76
 77
 78
 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
@pytest.mark.valid_at_transition_to("Amsterdam")
@pytest.mark.pre_alloc_mutable
@pytest.mark.parametrize("pre_fork_nonce", [1, 2, 32])
def test_factory_deploys_across_transition(
    blockchain_test: BlockchainTestFiller,
    pre: Alloc,
    pre_fork_nonce: int,
) -> None:
    """
    A pre-existing factory keeps deploying contracts across the Amsterdam
    transition, with its nonce accruing normally.

    Asserting that final nonce is what catches the glamsterdam-devnet-6 bug: a
    client that re-injects EIP-7997 at the transition resets the already-used
    factory back to nonce 1, diverging the post-state root. Deployment success
    alone cannot catch it, since the `CREATE2` address does not depend on the
    factory nonce.
    """
    factory = pre.deploy_contract(
        code=Spec.FACTORY_BYTECODE,
        address=Address(Spec.FACTORY_ADDRESS),
        nonce=pre_fork_nonce,
    )
    sender = pre.fund_eoa()

    runtime_code = Op.RETURN(0, 1)
    initcode = Initcode(deploy_code=runtime_code)

    timestamps = [FORK_TIMESTAMP - 1, FORK_TIMESTAMP, FORK_TIMESTAMP + 1]

    blocks = []
    deployed = {}
    for i, timestamp in enumerate(timestamps):
        blocks.append(
            Block(
                timestamp=timestamp,
                txs=[
                    Transaction(
                        sender=sender,
                        to=factory,
                        data=Hash(timestamp) + bytes(initcode),
                    )
                ],
                expected_block_access_list=BlockAccessListExpectation(
                    account_expectations={
                        factory: BalAccountExpectation(
                            nonce_changes=[
                                BalNonceChange(
                                    block_access_index=1,
                                    post_nonce=pre_fork_nonce + i + 1,
                                )
                            ],
                        ),
                    }
                ),
            )
        )
        deployed[compute_create2_address(factory, timestamp, initcode)] = (
            Account(nonce=1, code=bytes(runtime_code))
        )

    blockchain_test(
        pre=pre,
        blocks=blocks,
        post={
            **deployed,
            factory: Account(
                nonce=pre_fork_nonce + len(timestamps),
                code=Spec.FACTORY_BYTECODE,
            ),
        },
    )

Parametrized Test Cases

This test generates 3 parametrized test cases across 1 fork.