Skip to content

test_bal_7702_cross_tx_delegation_then_call()

Documentation for tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_cross_tx_delegation_then_call@9c2813ee.

Generate fixtures for these test cases for Amsterdam with:

fill -v tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py::test_bal_7702_cross_tx_delegation_then_call --fork Amsterdam

Verify clients apply Tx1's EIP-7702 delegation before later txs CALL the now-delegated EOA. Tx1 installs a delegation designator on alice pointing to a contract that increments slot 0. Tx2 and Tx3 CALL alice, so each later tx must observe both the installed code (Tx1) and the prior increment (the immediately preceding tx) for the final slot 0 to read 2. A client that parallelizes any tx against pre-block state would see no code or a stale counter, yielding a different state root.

Source code in tests/amsterdam/eip7928_block_level_access_lists/test_block_access_lists_eip7702.py
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
def test_bal_7702_cross_tx_delegation_then_call(
    pre: Alloc,
    blockchain_test: BlockchainTestFiller,
) -> None:
    """
    Verify clients apply Tx1's EIP-7702 delegation before later txs CALL
    the now-delegated EOA. Tx1 installs a delegation designator on `alice`
    pointing to a contract that increments slot 0. Tx2 and Tx3 CALL alice,
    so each later tx must observe both the installed code (Tx1) and the
    prior increment (the immediately preceding tx) for the final slot 0
    to read 2. A client that parallelizes any tx against pre-block state
    would see no code or a stale counter, yielding a different state root.
    """
    alice = pre.fund_eoa()
    bob = pre.fund_eoa()
    charlie = pre.fund_eoa()
    relayer = pre.fund_eoa()

    # Delegation target: increments slot 0 each time it's invoked.
    counter = pre.deploy_contract(
        code=Op.SSTORE(0, Op.ADD(Op.SLOAD(0), 1)),
    )

    tx_delegate = Transaction(
        sender=relayer,
        to=bob,
        value=0,
        gas_limit=1_000_000,
        authorization_list=[
            AuthorizationTuple(
                address=counter,
                nonce=0,
                signer=alice,
            )
        ],
    )
    tx_call_1 = Transaction(
        sender=bob,
        to=alice,
        gas_limit=200_000,
        gas_price=0xA,
    )
    tx_call_2 = Transaction(
        sender=charlie,
        to=alice,
        gas_limit=200_000,
        gas_price=0xA,
    )

    block = Block(
        txs=[tx_delegate, tx_call_1, tx_call_2],
        expected_block_access_list=BlockAccessListExpectation(
            account_expectations={
                alice: BalAccountExpectation(
                    nonce_changes=[
                        BalNonceChange(block_access_index=1, post_nonce=1),
                    ],
                    code_changes=[
                        BalCodeChange(
                            block_access_index=1,
                            new_code=Spec7702.delegation_designation(counter),
                        )
                    ],
                    storage_changes=[
                        BalStorageSlot(
                            slot=0,
                            slot_changes=[
                                BalStorageChange(
                                    block_access_index=2, post_value=1
                                ),
                                BalStorageChange(
                                    block_access_index=3, post_value=2
                                ),
                            ],
                        ),
                    ],
                ),
                # Delegation target: loaded as execution target on each
                # CALL to alice, but mutations land in alice's storage.
                counter: BalAccountExpectation.empty(),
            },
        ),
    )

    blockchain_test(
        pre=pre,
        blocks=[block],
        post={
            alice: Account(
                nonce=1,
                code=Spec7702.delegation_designation(counter),
                storage={0: 2},
            ),
        },
    )

Parametrized Test Cases

This test generates 1 parametrized test case across 1 fork.