Skip to content

Commit d07c5fa

Browse files
authored
fix(tests): EIP-7702: use penultimate block number instead of fixing block 0 (#1390)
* fix(tests): EIP-7702: use penultimate block number instead of fixing block 0 * fix(tests): EIP-7702: use contract code to get blocknumber instead of rpc
1 parent 3131f66 commit d07c5fa

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tests/prague/eip7702_set_code_tx/test_set_code_txs.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,17 +2703,32 @@ def test_set_code_to_system_contract(
27032703
caller_payload = consolidation_request.calldata
27042704
call_value = consolidation_request.value
27052705
case Address(0x0000F90827F1C53A10CB7A02335B175320002935): # EIP-2935
2706-
caller_payload = Hash(0)
2706+
# This payload is used to identify the number of blocks to be subtracted from the
2707+
# latest block number
2708+
caller_payload = Hash(1)
27072709
caller_code_storage[call_return_data_size_slot] = 32
27082710
case _:
27092711
raise ValueError(f"Not implemented system contract: {system_contract}")
27102712

2713+
# Setup the code to call the system contract
2714+
match system_contract:
2715+
case Address(0x0000F90827F1C53A10CB7A02335B175320002935): # EIP-2935
2716+
# Do a trick here to get the block number of the penultimate block to ensure it is
2717+
# saved in the history contract
2718+
check_block_number = Op.SUB(Op.NUMBER, Op.CALLDATALOAD(0))
2719+
call_system_contract_code = Op.MSTORE(0, check_block_number) + Op.SSTORE(
2720+
call_return_code_slot,
2721+
call_opcode(address=auth_signer, value=call_value, args_size=32),
2722+
)
2723+
case _:
2724+
# Call another system contract with fabricated payload
2725+
call_system_contract_code = Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE) + Op.SSTORE(
2726+
call_return_code_slot,
2727+
call_opcode(address=auth_signer, value=call_value, args_size=Op.CALLDATASIZE),
2728+
)
2729+
27112730
caller_code = (
2712-
Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE)
2713-
+ Op.SSTORE(
2714-
call_return_code_slot,
2715-
call_opcode(address=auth_signer, value=call_value, args_size=Op.CALLDATASIZE),
2716-
)
2731+
call_system_contract_code
27172732
+ Op.SSTORE(call_return_data_size_slot, Op.RETURNDATASIZE)
27182733
+ Op.STOP
27192734
)

0 commit comments

Comments
 (0)