Skip to content

Commit f86a779

Browse files
authored
fix(tests): EIP-2935: change ret_offset to avoid duplicate (#1349)
* fix(tests): EIP-2935: change retOffset to avoid duplicate * fix(tests): EIP-2935: reset contract return value after subtest
1 parent fe4fdf9 commit f86a779

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/prague/eip2935_historical_block_hashes_from_state/test_block_hashes.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def generate_block_check_code(
4343
check_contract_first (bool): Whether to check the contract first, for slot warming checks.
4444
4545
"""
46+
contract_ret_offset = 32
47+
4648
if check_block_number < 0:
4749
# Block number outside of range, nothing to check
4850
return Bytecode()
@@ -63,8 +65,8 @@ def generate_block_check_code(
6365
check_blockhash = Op.SSTORE(blockhash_key, Op.ISZERO(Op.BLOCKHASH(check_block_number)))
6466
check_contract = (
6567
Op.MSTORE(0, check_block_number)
66-
+ Op.POP(Op.CALL(Op.GAS, Spec.HISTORY_STORAGE_ADDRESS, 0, 0, 32, 0, 32))
67-
+ Op.SSTORE(contract_key, Op.ISZERO(Op.MLOAD(0)))
68+
+ Op.POP(Op.CALL(Op.GAS, Spec.HISTORY_STORAGE_ADDRESS, 0, 0, 32, contract_ret_offset, 32))
69+
+ Op.SSTORE(contract_key, Op.ISZERO(Op.MLOAD(contract_ret_offset)))
6870
)
6971

7072
if check_contract_first:
@@ -75,7 +77,12 @@ def generate_block_check_code(
7577
if populated_history_storage_contract and populated_blockhash:
7678
# Both values must be equal
7779
store_equal_key = storage.store_next(True)
78-
code += Op.SSTORE(store_equal_key, Op.EQ(Op.MLOAD(0), Op.BLOCKHASH(check_block_number)))
80+
code += Op.SSTORE(
81+
store_equal_key, Op.EQ(Op.MLOAD(contract_ret_offset), Op.BLOCKHASH(check_block_number))
82+
)
83+
84+
# Reset the contract return value
85+
code += Op.MSTORE(contract_ret_offset, 0)
7986

8087
return code
8188

0 commit comments

Comments
 (0)