Skip to content

Commit 75cdbb2

Browse files
committed
feat: add utils for prefix and code delegation + rm unused account
1 parent c5b70bf commit 75cdbb2

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

tracer/arithmetization/src/test/java/net/consensys/linea/zktracer/Utils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import static net.consensys.linea.reporting.TracerTestBase.chainConfig;
1919
import static net.consensys.linea.testing.BytecodeCompiler.newProgram;
2020

21+
import net.consensys.linea.testing.ToyAccount;
2122
import net.consensys.linea.zktracer.opcode.OpCode;
2223
import org.apache.tuweni.bytes.Bytes;
2324
import org.hyperledger.besu.datatypes.Address;
2425

2526
public class Utils {
27+
2628
public static final Bytes REVERT =
2729
newProgram(chainConfig).push(0).push(0).op(OpCode.REVERT).compile();
2830

@@ -61,4 +63,15 @@ public static Bytes delegateCall(Address address) {
6163
.op(OpCode.DELEGATECALL)
6264
.compile();
6365
}
66+
67+
// Utils for EIP-7702 tests
68+
69+
public static final String DELEGATION_PREFIX = "0xef0100";
70+
71+
public static String addDelegationPrefixToAccount(ToyAccount account) {
72+
return DELEGATION_PREFIX + account.getAddress().toHexString().substring(2);
73+
}
74+
public static String addDelegationPrefixToAddress(Address address) {
75+
return DELEGATION_PREFIX + address.toHexString().substring(2);
76+
}
6477
}

tracer/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/callTests/CallDelegation.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import java.util.List;
1919

20+
import static net.consensys.linea.zktracer.Utils.*;
21+
2022
/*
2123
2224
CALL DELEGATION TEST
@@ -71,7 +73,7 @@ public class CallDelegation extends TracerTestBase {
7173
.code(
7274
Bytes.concatenate(Bytes.fromHexString(smcBytecode)))
7375
.build();
74-
final String delegationCodeToSmc = "0xef0100" + smcAccount.getAddress().toHexString().substring(2);
76+
final String delegationCodeToSmc = addDelegationPrefixToAccount(smcAccount);
7577

7678
// Sender account setting
7779
final KeyPair keyPair = new SECP256K1().generateKeyPair();
@@ -125,7 +127,7 @@ void EOA1DelegatedEOA2(TestInfo testInfo) {
125127
.nonce(80)
126128
.build();
127129

128-
String delegationCodeToEoa2 = "0xef0100" + eoa2.getAddress().toHexString().substring(2);
130+
String delegationCodeToEoa2 = addDelegationPrefixToAccount(eoa2);
129131

130132
ToyAccount eoa1DelegatedToEoa2 =
131133
ToyAccount.builder()
@@ -141,7 +143,7 @@ void EOA1DelegatedEOA2(TestInfo testInfo) {
141143
.to(eoa1DelegatedToEoa2).build();
142144

143145
ToyExecutionEnvironmentV2.builder(chainConfig, testInfo)
144-
.accounts(List.of(senderAccount, smcAccount, eoa1DelegatedToEoa2, eoa2))
146+
.accounts(List.of(senderAccount, eoa1DelegatedToEoa2, eoa2))
145147
.transaction(tx)
146148
.build()
147149
.run();
@@ -159,7 +161,7 @@ void EOADelegatedToItself(TestInfo testInfo) {
159161

160162
Address eoaAddress = Address.fromHexString("ca11ee1");
161163

162-
String delegationCodeToEoa = "0xef0100" + eoaAddress.toHexString().substring(2);
164+
String delegationCodeToEoa = addDelegationPrefixToAddress(eoaAddress);
163165

164166
ToyAccount eoa =
165167
ToyAccount.builder()
@@ -175,7 +177,7 @@ void EOADelegatedToItself(TestInfo testInfo) {
175177
.to(eoa).build();
176178

177179
ToyExecutionEnvironmentV2.builder(chainConfig, testInfo)
178-
.accounts(List.of(senderAccount,eoa ))
180+
.accounts(List.of(senderAccount, eoa))
179181
.transaction(tx)
180182
.build()
181183
.run();
@@ -200,7 +202,7 @@ void EOA1DelegatedEOA2DelegatedToSmc(TestInfo testInfo) {
200202
Bytes.concatenate(Bytes.fromHexString(delegationCodeToSmc)))
201203
.build();
202204

203-
String delegationCodeToEoa2 = "0xef0100" + eoa2DelegatedToSmc.getAddress().toHexString().substring(2);
205+
String delegationCodeToEoa2 = addDelegationPrefixToAccount(eoa2DelegatedToSmc);
204206

205207
ToyAccount eoa1DelegatedToEoa2 =
206208
ToyAccount.builder()
@@ -232,8 +234,7 @@ void EOA1DelegatedEOA2DelegatedToSmc(TestInfo testInfo) {
232234
@Test
233235
void targetIsPrc(TestInfo testInfo) {
234236

235-
String delegationCodeToP256Verify = "0xef0100" + Address.P256_VERIFY.toHexString().substring(2);
236-
237+
String delegationCodeToP256Verify = addDelegationPrefixToAddress(Address.P256_VERIFY);
237238
ToyAccount eoaDelegatedToPrc =
238239
ToyAccount.builder()
239240
.address(Address.fromHexString("ca11ee")) // identity caller

0 commit comments

Comments
 (0)