Skip to content

Commit

Permalink
Merge branch 'eip-7702' into devnet-1
Browse files Browse the repository at this point in the history
  • Loading branch information
marioevz committed Jul 10, 2024
2 parents ad60689 + 835efb6 commit 51749d1
Showing 1 changed file with 143 additions and 10 deletions.
153 changes: 143 additions & 10 deletions tests/prague/eip7702_eoa_code_tx/test_eoa_code_txs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
Account,
Alloc,
AuthorizationTuple,
Block,
BlockchainTestFiller,
Bytecode,
Conditional,
Environment,
Expand Down Expand Up @@ -97,7 +99,7 @@ def test_set_code_to_sstore(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand All @@ -111,6 +113,137 @@ def test_set_code_to_sstore(
)


def test_set_code_to_sstore_then_sload(
blockchain_test: BlockchainTestFiller,
pre: Alloc,
):
"""
Test the executing a simple SSTORE then SLOAD in two separate set-code transactions.
"""
auth_signer = pre.fund_eoa(auth_account_start_balance)
sender = pre.fund_eoa()

storage_key_1 = 0x1
storage_key_2 = 0x2
storage_value = 0x1234

set_code_1 = Op.SSTORE(storage_key_1, storage_value) + Op.STOP
set_code_1_address = pre.deploy_contract(set_code_1)

set_code_2 = Op.SSTORE(storage_key_2, Op.ADD(Op.SLOAD(storage_key_1), 1)) + Op.STOP
set_code_2_address = pre.deploy_contract(set_code_2)

tx_1 = Transaction(
gas_limit=50_000,
to=auth_signer,
value=0,
authorization_list=[
AuthorizationTuple(
address=set_code_1_address,
nonce=0,
signer=auth_signer,
),
],
sender=sender,
)

tx_2 = Transaction(
gas_limit=50_000,
to=auth_signer,
value=0,
authorization_list=[
AuthorizationTuple(
address=set_code_2_address,
nonce=0,
signer=auth_signer,
),
],
sender=sender,
)

block = Block(
txs=[tx_1, tx_2],
)

blockchain_test(
pre=pre,
post={
auth_signer: Account(
nonce=0,
code=b"",
storage={
storage_key_1: storage_value,
storage_key_2: storage_value + 1,
},
),
},
blocks=[block],
)


@pytest.mark.parametrize(
"call_opcode",
[
Op.CALL,
Op.DELEGATECALL,
Op.STATICCALL,
Op.CALLCODE,
],
)
@pytest.mark.parametrize(
"return_opcode",
[
Op.RETURN,
Op.REVERT,
],
)
def test_set_code_to_tstore_reentry(
state_test: StateTestFiller,
pre: Alloc,
call_opcode: Op,
return_opcode: Op,
):
"""
Test the executing a simple TSTORE in a set-code transaction, which also performs a
re-entry to TLOAD the value.
"""
auth_signer = pre.fund_eoa(auth_account_start_balance)

tload_value = 0x1234
set_code = Conditional(
condition=Op.ISZERO(Op.TLOAD(1)),
if_true=Op.TSTORE(1, tload_value)
+ call_opcode(address=Op.ADDRESS)
+ Op.RETURNDATACOPY(0, 0, 32)
+ Op.SSTORE(2, Op.MLOAD(0)),
if_false=Op.MSTORE(0, Op.TLOAD(1)) + return_opcode(size=32),
)
set_code_to_address = pre.deploy_contract(set_code)

tx = Transaction(
gas_limit=100_000,
to=auth_signer,
value=0,
authorization_list=[
AuthorizationTuple(
address=set_code_to_address,
nonce=0,
signer=auth_signer,
),
],
sender=pre.fund_eoa(),
)

state_test(
env=Environment(),
pre=pre,
tx=tx,
post={
auth_signer: Account(nonce=0, code=b"", storage={2: tload_value}),
},
)


def test_set_code_to_self_destruct(
state_test: StateTestFiller,
pre: Alloc,
Expand All @@ -133,7 +266,7 @@ def test_set_code_to_self_destruct(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -192,7 +325,7 @@ def test_set_code_to_contract_creator(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -389,7 +522,7 @@ def test_address_from_set_code(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -461,7 +594,7 @@ def test_ext_code_on_set_code(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -522,7 +655,7 @@ def test_self_code_on_set_code(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -599,7 +732,7 @@ def test_set_code_to_account_deployed_in_same_tx(
signer=auth_signer,
),
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -655,7 +788,7 @@ def test_set_code_multiple_valid_authorization_tuples_same_signer(
)
for address in addresses
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -704,7 +837,7 @@ def test_set_code_multiple_valid_authorization_tuples_first_invalid_same_signer(
)
for i, address in enumerate(addresses)
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down Expand Up @@ -764,7 +897,7 @@ def test_set_code_invalid_authorization_tuple(
signer=auth_signer,
)
],
sender=pre.fund_eoa(10**18),
sender=pre.fund_eoa(),
)

state_test(
Expand Down

0 comments on commit 51749d1

Please sign in to comment.