Skip to content

test_reentrant_eofcreate()

Documentation for tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_reentrant_eofcreate@bc691d13.

Generate fixtures for these test cases for Osaka with:

fill -v tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py::test_reentrant_eofcreate --fork Osaka

Verifies a reentrant EOFCREATE case, where EIP-161 prevents conflict via nonce bump.

Source code in tests/osaka/eip7692_eof_v1/eip7620_eof_create/test_eofcreate_failures.py
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
def test_reentrant_eofcreate(
    state_test: StateTestFiller,
    pre: Alloc,
):
    """Verifies a reentrant EOFCREATE case, where EIP-161 prevents conflict via nonce bump."""
    env = Environment()
    # Calls into the factory contract with 1 as input.
    reenter_code = Op.MSTORE(0, 1) + Op.EXTCALL(address=Op.CALLDATALOAD(32), args_size=32)
    # Initcode: if given 0 as 1st word of input will call into the factory again.
    #           2nd word of input is the address of the factory.
    initcontainer = Container(
        sections=[
            Section.Code(
                Op.SSTORE(slot_counter, Op.ADD(Op.SLOAD(slot_counter), 1))
                + Op.CALLDATALOAD(0)
                + Op.RJUMPI[len(reenter_code)]
                + reenter_code
                + Op.RETURNCODE[0](0, 0)
            ),
            Section.Container(smallest_runtime_subcontainer),
        ]
    )
    # Factory: Passes on its input into the initcode. It's 0 first time, 1 the second time.
    #          Saves the result of deployment in slot 0 first time, 1 the second time.
    contract_address = pre.deploy_contract(
        code=Container(
            sections=[
                Section.Code(
                    Op.CALLDATACOPY(0, 0, 32)
                    + Op.MSTORE(32, Op.ADDRESS)
                    # 1st word - copied from input (reenter flag), 2nd word - `this.address`.
                    + Op.SSTORE(Op.CALLDATALOAD(0), Op.EOFCREATE[0](input_size=64))
                    + Op.STOP,
                ),
                Section.Container(initcontainer),
            ],
        ),
        storage={0: 0xB17D, 1: 0xB17D},  # a canary to be overwritten
    )
    # Flow is: reenter flag 0 -> factory -> reenter flag 0 -> initcode -> reenter ->
    #          reenter flag 1 -> factory -> reenter flag 1 -> (!) initcode -> stop,
    # if the EIP-161 nonce bump is not implemented. If it is, it fails before second
    # inicode marked (!).
    # Storage in 0 should have the address from the outer EOFCREATE.
    # Storage in 1 should have 0 from the inner EOFCREATE.
    # For the created contract storage in `slot_counter` should be 1 as initcode executes only once
    post = {
        contract_address: Account(
            storage={
                0: compute_eofcreate_address(contract_address, 0),
                1: 0,
            }
        ),
        compute_eofcreate_address(contract_address, 0): Account(
            nonce=1, code=smallest_runtime_subcontainer, storage={slot_counter: 1}
        ),
    }
    tx = Transaction(
        to=contract_address,
        gas_limit=500_000,
        sender=pre.fund_eoa(),
    )
    state_test(env=env, pre=pre, post=post, tx=tx)

Parametrized Test Cases

This test case is only parametrized by fork and fixture format.

Test ID (Abbreviated)
...fork_Osaka-state_test
...fork_Osaka-blockchain_test_from_state_test