1212 Account ,
1313 Alloc ,
1414 AuthorizationTuple ,
15+ Block ,
16+ BlockchainTestFiller ,
1517 Bytecode ,
1618 Conditional ,
1719 Environment ,
@@ -97,7 +99,7 @@ def test_set_code_to_sstore(
9799 signer = auth_signer ,
98100 ),
99101 ],
100- sender = pre .fund_eoa (10 ** 18 ),
102+ sender = pre .fund_eoa (),
101103 )
102104
103105 state_test (
@@ -111,6 +113,137 @@ def test_set_code_to_sstore(
111113 )
112114
113115
116+ def test_set_code_to_sstore_then_sload (
117+ blockchain_test : BlockchainTestFiller ,
118+ pre : Alloc ,
119+ ):
120+ """
121+ Test the executing a simple SSTORE then SLOAD in two separate set-code transactions.
122+ """
123+ auth_signer = pre .fund_eoa (auth_account_start_balance )
124+ sender = pre .fund_eoa ()
125+
126+ storage_key_1 = 0x1
127+ storage_key_2 = 0x2
128+ storage_value = 0x1234
129+
130+ set_code_1 = Op .SSTORE (storage_key_1 , storage_value ) + Op .STOP
131+ set_code_1_address = pre .deploy_contract (set_code_1 )
132+
133+ set_code_2 = Op .SSTORE (storage_key_2 , Op .ADD (Op .SLOAD (storage_key_1 ), 1 )) + Op .STOP
134+ set_code_2_address = pre .deploy_contract (set_code_2 )
135+
136+ tx_1 = Transaction (
137+ gas_limit = 50_000 ,
138+ to = auth_signer ,
139+ value = 0 ,
140+ authorization_list = [
141+ AuthorizationTuple (
142+ address = set_code_1_address ,
143+ nonce = 0 ,
144+ signer = auth_signer ,
145+ ),
146+ ],
147+ sender = sender ,
148+ )
149+
150+ tx_2 = Transaction (
151+ gas_limit = 50_000 ,
152+ to = auth_signer ,
153+ value = 0 ,
154+ authorization_list = [
155+ AuthorizationTuple (
156+ address = set_code_2_address ,
157+ nonce = 0 ,
158+ signer = auth_signer ,
159+ ),
160+ ],
161+ sender = sender ,
162+ )
163+
164+ block = Block (
165+ txs = [tx_1 , tx_2 ],
166+ )
167+
168+ blockchain_test (
169+ pre = pre ,
170+ post = {
171+ auth_signer : Account (
172+ nonce = 0 ,
173+ code = b"" ,
174+ storage = {
175+ storage_key_1 : storage_value ,
176+ storage_key_2 : storage_value + 1 ,
177+ },
178+ ),
179+ },
180+ blocks = [block ],
181+ )
182+
183+
184+ @pytest .mark .parametrize (
185+ "call_opcode" ,
186+ [
187+ Op .CALL ,
188+ Op .DELEGATECALL ,
189+ Op .STATICCALL ,
190+ Op .CALLCODE ,
191+ ],
192+ )
193+ @pytest .mark .parametrize (
194+ "return_opcode" ,
195+ [
196+ Op .RETURN ,
197+ Op .REVERT ,
198+ ],
199+ )
200+ def test_set_code_to_tstore_reentry (
201+ state_test : StateTestFiller ,
202+ pre : Alloc ,
203+ call_opcode : Op ,
204+ return_opcode : Op ,
205+ ):
206+ """
207+ Test the executing a simple TSTORE in a set-code transaction, which also performs a
208+ re-entry to TLOAD the value.
209+ """
210+ auth_signer = pre .fund_eoa (auth_account_start_balance )
211+
212+ tload_value = 0x1234
213+ set_code = Conditional (
214+ condition = Op .ISZERO (Op .TLOAD (1 )),
215+ if_true = Op .TSTORE (1 , tload_value )
216+ + call_opcode (address = Op .ADDRESS )
217+ + Op .RETURNDATACOPY (0 , 0 , 32 )
218+ + Op .SSTORE (2 , Op .MLOAD (0 )),
219+ if_false = Op .MSTORE (0 , Op .TLOAD (1 )) + return_opcode (size = 32 ),
220+ )
221+ set_code_to_address = pre .deploy_contract (set_code )
222+
223+ tx = Transaction (
224+ gas_limit = 100_000 ,
225+ to = auth_signer ,
226+ value = 0 ,
227+ authorization_list = [
228+ AuthorizationTuple (
229+ address = set_code_to_address ,
230+ nonce = 0 ,
231+ signer = auth_signer ,
232+ ),
233+ ],
234+ sender = pre .fund_eoa (),
235+ )
236+
237+ state_test (
238+ env = Environment (),
239+ pre = pre ,
240+ tx = tx ,
241+ post = {
242+ auth_signer : Account (nonce = 0 , code = b"" , storage = {2 : tload_value }),
243+ },
244+ )
245+
246+
114247def test_set_code_to_self_destruct (
115248 state_test : StateTestFiller ,
116249 pre : Alloc ,
@@ -133,7 +266,7 @@ def test_set_code_to_self_destruct(
133266 signer = auth_signer ,
134267 ),
135268 ],
136- sender = pre .fund_eoa (10 ** 18 ),
269+ sender = pre .fund_eoa (),
137270 )
138271
139272 state_test (
@@ -192,7 +325,7 @@ def test_set_code_to_contract_creator(
192325 signer = auth_signer ,
193326 ),
194327 ],
195- sender = pre .fund_eoa (10 ** 18 ),
328+ sender = pre .fund_eoa (),
196329 )
197330
198331 state_test (
@@ -389,7 +522,7 @@ def test_address_from_set_code(
389522 signer = auth_signer ,
390523 ),
391524 ],
392- sender = pre .fund_eoa (10 ** 18 ),
525+ sender = pre .fund_eoa (),
393526 )
394527
395528 state_test (
@@ -461,7 +594,7 @@ def test_ext_code_on_set_code(
461594 signer = auth_signer ,
462595 ),
463596 ],
464- sender = pre .fund_eoa (10 ** 18 ),
597+ sender = pre .fund_eoa (),
465598 )
466599
467600 state_test (
@@ -522,7 +655,7 @@ def test_self_code_on_set_code(
522655 signer = auth_signer ,
523656 ),
524657 ],
525- sender = pre .fund_eoa (10 ** 18 ),
658+ sender = pre .fund_eoa (),
526659 )
527660
528661 state_test (
@@ -599,7 +732,7 @@ def test_set_code_to_account_deployed_in_same_tx(
599732 signer = auth_signer ,
600733 ),
601734 ],
602- sender = pre .fund_eoa (10 ** 18 ),
735+ sender = pre .fund_eoa (),
603736 )
604737
605738 state_test (
@@ -655,7 +788,7 @@ def test_set_code_multiple_valid_authorization_tuples_same_signer(
655788 )
656789 for address in addresses
657790 ],
658- sender = pre .fund_eoa (10 ** 18 ),
791+ sender = pre .fund_eoa (),
659792 )
660793
661794 state_test (
@@ -704,7 +837,7 @@ def test_set_code_multiple_valid_authorization_tuples_first_invalid_same_signer(
704837 )
705838 for i , address in enumerate (addresses )
706839 ],
707- sender = pre .fund_eoa (10 ** 18 ),
840+ sender = pre .fund_eoa (),
708841 )
709842
710843 state_test (
@@ -764,7 +897,7 @@ def test_set_code_invalid_authorization_tuple(
764897 signer = auth_signer ,
765898 )
766899 ],
767- sender = pre .fund_eoa (10 ** 18 ),
900+ sender = pre .fund_eoa (),
768901 )
769902
770903 state_test (
0 commit comments