Skip to content

Commit d10557d

Browse files
committed
Simplify getter tests to use RETURNDATACOPY instead of ret buffer
Co-Authored-By: Claude claude-opus-4-6
1 parent 0005f48 commit d10557d

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

tests/monad_eight/staking_precompile/test_getters.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
)
1717
from execution_testing.forks.helpers import Fork
1818

19-
from .helpers import build_calldata, generous_gas
19+
from .helpers import (
20+
CORRECT_SEL_ARGS_OFFSET,
21+
build_calldata,
22+
calldata_mem_end,
23+
generous_gas,
24+
)
2025
from .spec import (
2126
GETTER_FUNCTIONS,
2227
STAKING_PRECOMPILE,
@@ -60,28 +65,23 @@ def test_getter_return_data(
6065
word of the return data.
6166
"""
6267
num_words = func.return_size // 32
68+
rdc_offset = calldata_mem_end(func.calldata_size)
6369

64-
# Build contract: call getter, store RETURNDATASIZE, then
65-
# copy return data and store each word
66-
ret_offset = 256
6770
contract = (
6871
build_calldata(func.selector, func.calldata_size)
6972
+ Op.SSTORE(
7073
slot_call_success,
7174
Op.CALL(
7275
gas=func.gas_cost + 10000,
7376
address=STAKING_PRECOMPILE,
74-
args_offset=60,
77+
args_offset=CORRECT_SEL_ARGS_OFFSET,
7578
args_size=func.calldata_size,
76-
ret_offset=ret_offset,
77-
ret_size=func.return_size,
7879
),
7980
)
8081
+ Op.SSTORE(slot_return_size, Op.RETURNDATASIZE)
8182
)
8283

8384
if num_words > 0:
84-
rdc_offset = ret_offset + func.return_size + 32
8585
contract += Op.RETURNDATACOPY(rdc_offset, 0, Op.RETURNDATASIZE)
8686
contract += Op.SSTORE(slot_return_word_base, Op.MLOAD(rdc_offset))
8787

@@ -132,41 +132,36 @@ def test_getter_idempotent(
132132
slot_success_1 = 0x24
133133
slot_success_2 = 0x25
134134

135-
ret_offset_1 = 256
136-
ret_offset_2 = ret_offset_1 + func.return_size + 64
137-
138-
calldata_setup = build_calldata(func.selector, func.calldata_size)
135+
rdc_offset = calldata_mem_end(func.calldata_size)
139136

140137
contract = (
141-
calldata_setup
138+
build_calldata(func.selector, func.calldata_size)
142139
# First call
143140
+ Op.SSTORE(
144141
slot_success_1,
145142
Op.CALL(
146143
gas=func.gas_cost + 10000,
147144
address=STAKING_PRECOMPILE,
148-
args_offset=60,
145+
args_offset=CORRECT_SEL_ARGS_OFFSET,
149146
args_size=func.calldata_size,
150-
ret_offset=ret_offset_1,
151-
ret_size=func.return_size,
152147
),
153148
)
154149
+ Op.SSTORE(slot_size_1, Op.RETURNDATASIZE)
155-
+ Op.SSTORE(slot_word_1, Op.MLOAD(ret_offset_1))
150+
+ Op.RETURNDATACOPY(rdc_offset, 0, Op.RETURNDATASIZE)
151+
+ Op.SSTORE(slot_word_1, Op.MLOAD(rdc_offset))
156152
# Second call (same calldata still in memory)
157153
+ Op.SSTORE(
158154
slot_success_2,
159155
Op.CALL(
160156
gas=func.gas_cost + 10000,
161157
address=STAKING_PRECOMPILE,
162-
args_offset=60,
158+
args_offset=CORRECT_SEL_ARGS_OFFSET,
163159
args_size=func.calldata_size,
164-
ret_offset=ret_offset_2,
165-
ret_size=func.return_size,
166160
),
167161
)
168162
+ Op.SSTORE(slot_size_2, Op.RETURNDATASIZE)
169-
+ Op.SSTORE(slot_word_2, Op.MLOAD(ret_offset_2))
163+
+ Op.RETURNDATACOPY(rdc_offset, 0, Op.RETURNDATASIZE)
164+
+ Op.SSTORE(slot_word_2, Op.MLOAD(rdc_offset))
170165
+ Op.SSTORE(slot_code_worked, value_code_worked)
171166
)
172167
contract_address = pre.deploy_contract(contract)

0 commit comments

Comments
 (0)