11package net .consensys .linea .zktracer .instructionprocessing .callTests ;
22
3+ import static net .consensys .linea .zktracer .Utils .*;
4+
5+ import java .util .List ;
36import net .consensys .linea .reporting .TracerTestBase ;
47import net .consensys .linea .testing .ToyAccount ;
58import net .consensys .linea .testing .ToyExecutionEnvironmentV2 ;
1518import org .junit .jupiter .api .Test ;
1619import org .junit .jupiter .api .TestInfo ;
1720
18- import java .util .List ;
19-
20- import static net .consensys .linea .zktracer .Utils .*;
21-
2221/*
2322
2423CALL DELEGATION TEST
5958public class CallDelegation extends TracerTestBase {
6059
6160 /* Smart contract byte code
62- ADDRESS
63- SELFBALANCE
64- CODESIZE
65- CALLER
66- CALLVALUE
67- GAS
68- */
61+ ADDRESS
62+ SELFBALANCE
63+ CODESIZE
64+ CALLER
65+ CALLVALUE
66+ GAS
67+ */
6968
7069 final String smcBytecode = "0x30473833345a" ;
7170 final ToyAccount smcAccount =
72- ToyAccount .builder ()
73- .address (Address .fromHexString ("1234" ))
74- .nonce (90 )
75- .code (
76- Bytes .concatenate (Bytes .fromHexString (smcBytecode )))
77- .build ();
71+ ToyAccount .builder ()
72+ .address (Address .fromHexString ("1234" ))
73+ .nonce (90 )
74+ .code (Bytes .concatenate (Bytes .fromHexString (smcBytecode )))
75+ .build ();
7876 final String delegationCodeToSmc = addDelegationPrefixToAccount (smcAccount );
7977
8078 // Sender account setting
8179 final KeyPair keyPair = new SECP256K1 ().generateKeyPair ();
82- final Address senderAddress = Address .extract (Hash .hash (keyPair .getPublicKey ().getEncodedBytes ()));
80+ final Address senderAddress =
81+ Address .extract (Hash .hash (keyPair .getPublicKey ().getEncodedBytes ()));
8382 final ToyAccount senderAccount =
84- ToyAccount .builder ().balance (Wei .of (1_550_000_000_000L )).nonce (23 ).address (senderAddress ).build ();
83+ ToyAccount .builder ()
84+ .balance (Wei .of (1_550_000_000_000L ))
85+ .nonce (23 )
86+ .address (senderAddress )
87+ .build ();
8588
8689 /*
8790 (1) TARGET is a Smart Contract
@@ -94,23 +97,24 @@ public class CallDelegation extends TracerTestBase {
9497 void EOADelegatedToSmc (TestInfo testInfo ) {
9598
9699 ToyAccount eoaDelegatedToSmc =
97- ToyAccount .builder ()
98- .address (Address .fromHexString ("ca11ee" )) // identity caller
99- .nonce (99 )
100- .code (
101- Bytes .concatenate (Bytes .fromHexString (delegationCodeToSmc )))
102- .build ();
103-
104- Transaction tx = ToyTransaction .builder ()
105- .sender (senderAccount )
106- .keyPair (keyPair )
107- .to (eoaDelegatedToSmc ).build ();
100+ ToyAccount .builder ()
101+ .address (Address .fromHexString ("ca11ee" )) // identity caller
102+ .nonce (99 )
103+ .code (Bytes .concatenate (Bytes .fromHexString (delegationCodeToSmc )))
104+ .build ();
105+
106+ Transaction tx =
107+ ToyTransaction .builder ()
108+ .sender (senderAccount )
109+ .keyPair (keyPair )
110+ .to (eoaDelegatedToSmc )
111+ .build ();
108112
109113 ToyExecutionEnvironmentV2 .builder (chainConfig , testInfo )
110- .accounts (List .of (senderAccount , smcAccount , eoaDelegatedToSmc ))
111- .transaction (tx )
112- .build ()
113- .run ();
114+ .accounts (List .of (senderAccount , smcAccount , eoaDelegatedToSmc ))
115+ .transaction (tx )
116+ .build ()
117+ .run ();
114118 }
115119
116120 /*
@@ -124,31 +128,32 @@ void EOADelegatedToSmc(TestInfo testInfo) {
124128 void EOA1DelegatedEOA2 (TestInfo testInfo ) {
125129
126130 ToyAccount eoa2 =
127- ToyAccount .builder ()
128- .address (Address .fromHexString ("ca11ee2" )) // identity caller
129- .nonce (80 )
130- .build ();
131+ ToyAccount .builder ()
132+ .address (Address .fromHexString ("ca11ee2" )) // identity caller
133+ .nonce (80 )
134+ .build ();
131135
132136 String delegationCodeToEoa2 = addDelegationPrefixToAccount (eoa2 );
133137
134138 ToyAccount eoa1DelegatedToEoa2 =
135- ToyAccount .builder ()
136- .address (Address .fromHexString ("ca11ee1" )) // identity caller
137- .nonce (99 )
138- .code (
139- Bytes .concatenate (Bytes .fromHexString (delegationCodeToEoa2 )))
140- .build ();
141-
142- Transaction tx = ToyTransaction .builder ()
143- .sender (senderAccount )
144- .keyPair (keyPair )
145- .to (eoa1DelegatedToEoa2 ).build ();
139+ ToyAccount .builder ()
140+ .address (Address .fromHexString ("ca11ee1" )) // identity caller
141+ .nonce (99 )
142+ .code (Bytes .concatenate (Bytes .fromHexString (delegationCodeToEoa2 )))
143+ .build ();
144+
145+ Transaction tx =
146+ ToyTransaction .builder ()
147+ .sender (senderAccount )
148+ .keyPair (keyPair )
149+ .to (eoa1DelegatedToEoa2 )
150+ .build ();
146151
147152 ToyExecutionEnvironmentV2 .builder (chainConfig , testInfo )
148- .accounts (List .of (senderAccount , eoa1DelegatedToEoa2 , eoa2 ))
149- .transaction (tx )
150- .build ()
151- .run ();
153+ .accounts (List .of (senderAccount , eoa1DelegatedToEoa2 , eoa2 ))
154+ .transaction (tx )
155+ .build ()
156+ .run ();
152157 }
153158
154159 /*
@@ -166,95 +171,92 @@ void EOADelegatedToItself(TestInfo testInfo) {
166171 String delegationCodeToEoa = addDelegationPrefixToAddress (eoaAddress );
167172
168173 ToyAccount eoa =
169- ToyAccount .builder ()
170- .address (Address .fromHexString ("ca11ee1" )) // identity caller
171- .nonce (99 )
172- .code (
173- Bytes .concatenate (Bytes .fromHexString (delegationCodeToEoa )))
174- .build ();
174+ ToyAccount .builder ()
175+ .address (Address .fromHexString ("ca11ee1" )) // identity caller
176+ .nonce (99 )
177+ .code (Bytes .concatenate (Bytes .fromHexString (delegationCodeToEoa )))
178+ .build ();
175179
176- Transaction tx = ToyTransaction .builder ()
177- .sender (senderAccount )
178- .keyPair (keyPair )
179- .to (eoa ).build ();
180+ Transaction tx =
181+ ToyTransaction .builder ().sender (senderAccount ).keyPair (keyPair ).to (eoa ).build ();
180182
181183 ToyExecutionEnvironmentV2 .builder (chainConfig , testInfo )
182- .accounts (List .of (senderAccount , eoa ))
183- .transaction (tx )
184- .build ()
185- .run ();
184+ .accounts (List .of (senderAccount , eoa ))
185+ .transaction (tx )
186+ .build ()
187+ .run ();
186188 }
187189
188190 /*
189- (4) TARGET is an EOA delegated to another EOA
190- CALL
191- --------> - EOA1
192- |---------------> EOA2
193- (delegated to) |---------------> Smart Contract
194- (delegated to)
195- */
191+ (4) TARGET is an EOA delegated to another EOA
192+ CALL
193+ --------> - EOA1
194+ |---------------> EOA2
195+ (delegated to) |---------------> Smart Contract
196+ (delegated to)
197+ */
196198 @ Test
197199 void EOA1DelegatedEOA2DelegatedToSmc (TestInfo testInfo ) {
198200
199201 ToyAccount eoa2DelegatedToSmc =
200- ToyAccount .builder ()
201- .address (Address .fromHexString ("ca11ee2" )) // identity caller
202- .nonce (80 )
203- .code (
204- Bytes .concatenate (Bytes .fromHexString (delegationCodeToSmc )))
205- .build ();
202+ ToyAccount .builder ()
203+ .address (Address .fromHexString ("ca11ee2" )) // identity caller
204+ .nonce (80 )
205+ .code (Bytes .concatenate (Bytes .fromHexString (delegationCodeToSmc )))
206+ .build ();
206207
207- String delegationCodeToEoa2 = addDelegationPrefixToAccount (eoa2DelegatedToSmc );
208+ String delegationCodeToEoa2 = addDelegationPrefixToAccount (eoa2DelegatedToSmc );
208209
209210 ToyAccount eoa1DelegatedToEoa2 =
210- ToyAccount .builder ()
211- .address (Address .fromHexString ("ca11ee1" )) // identity caller
212- .nonce (99 )
213- .code (
214- Bytes .concatenate (Bytes .fromHexString (delegationCodeToEoa2 )))
215- .build ();
216-
217- Transaction tx = ToyTransaction .builder ()
218- .sender (senderAccount )
219- .keyPair (keyPair )
220- .to (eoa1DelegatedToEoa2 ).build ();
211+ ToyAccount .builder ()
212+ .address (Address .fromHexString ("ca11ee1" )) // identity caller
213+ .nonce (99 )
214+ .code (Bytes .concatenate (Bytes .fromHexString (delegationCodeToEoa2 )))
215+ .build ();
216+
217+ Transaction tx =
218+ ToyTransaction .builder ()
219+ .sender (senderAccount )
220+ .keyPair (keyPair )
221+ .to (eoa1DelegatedToEoa2 )
222+ .build ();
221223
222224 ToyExecutionEnvironmentV2 .builder (chainConfig , testInfo )
223- .accounts (List .of (senderAccount , smcAccount , eoa1DelegatedToEoa2 , eoa2DelegatedToSmc ))
224- .transaction (tx )
225- .build ()
226- .run ();
225+ .accounts (List .of (senderAccount , smcAccount , eoa1DelegatedToEoa2 , eoa2DelegatedToSmc ))
226+ .transaction (tx )
227+ .build ()
228+ .run ();
227229 }
228230
229231 /*
230- (5) TARGET is a precompile
231- CALL
232- --------> - EOA
233- |---------------> PRC, here P256_VERIFY
234- (delegated to)
235- */
232+ (5) TARGET is a precompile
233+ CALL
234+ --------> - EOA
235+ |---------------> PRC, here P256_VERIFY
236+ (delegated to)
237+ */
236238 @ Test
237239 void targetIsPrc (TestInfo testInfo ) {
238240
239241 String delegationCodeToP256Verify = addDelegationPrefixToAddress (Address .P256_VERIFY );
240242 ToyAccount eoaDelegatedToPrc =
241- ToyAccount .builder ()
242- .address (Address .fromHexString ("ca11ee" )) // identity caller
243- .nonce (99 )
244- .code (
245- Bytes .concatenate (Bytes .fromHexString (delegationCodeToP256Verify )))
246- .build ();
247-
248- Transaction tx = ToyTransaction .builder ()
249- .sender (senderAccount )
250- .keyPair (keyPair )
251- .to (eoaDelegatedToPrc ).build ();
243+ ToyAccount .builder ()
244+ .address (Address .fromHexString ("ca11ee" )) // identity caller
245+ .nonce (99 )
246+ .code (Bytes .concatenate (Bytes .fromHexString (delegationCodeToP256Verify )))
247+ .build ();
248+
249+ Transaction tx =
250+ ToyTransaction .builder ()
251+ .sender (senderAccount )
252+ .keyPair (keyPair )
253+ .to (eoaDelegatedToPrc )
254+ .build ();
252255
253256 ToyExecutionEnvironmentV2 .builder (chainConfig , testInfo )
254- .accounts (List .of (senderAccount , eoaDelegatedToPrc ))
255- .transaction (tx )
256- .build ()
257- .run ();
257+ .accounts (List .of (senderAccount , eoaDelegatedToPrc ))
258+ .transaction (tx )
259+ .build ()
260+ .run ();
258261 }
259-
260262}
0 commit comments