Skip to content

Commit 0588894

Browse files
authored
Feat/multi transaction with create tests (#1615)
1 parent 4e712f9 commit 0588894

File tree

5 files changed

+88
-53
lines changed

5 files changed

+88
-53
lines changed

tracer/arithmetization/src/test/java/net/consensys/linea/zktracer/instructionprocessing/createTests/failure/CreateInducedFailureTest.java

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
package net.consensys.linea.zktracer.instructionprocessing.createTests.failure;
1616

17+
import static net.consensys.linea.testing.ToyTransaction.ToyTransactionBuilder;
1718
import static net.consensys.linea.zktracer.instructionprocessing.createTests.trivial.RootLevel.salt01;
1819
import static net.consensys.linea.zktracer.instructionprocessing.utilities.MonoOpCodeSmcs.keyPair;
1920
import static net.consensys.linea.zktracer.instructionprocessing.utilities.MonoOpCodeSmcs.userAccount;
@@ -27,6 +28,7 @@
2728
import net.consensys.linea.testing.BytecodeCompiler;
2829
import net.consensys.linea.testing.ToyAccount;
2930
import net.consensys.linea.testing.ToyExecutionEnvironmentV2;
31+
import net.consensys.linea.testing.ToyMultiTransaction;
3032
import net.consensys.linea.testing.ToyTransaction;
3133
import org.apache.tuweni.bytes.Bytes;
3234
import org.hyperledger.besu.datatypes.Address;
@@ -41,26 +43,27 @@
4143
*
4244
* <p>- we start with an account {@link #entryPoint};
4345
*
44-
* <p>- in {@link #transactionDeployingDelegateCaller} we call {@link #entryPoint} with empty call
45-
* data which leads to the deployment of {@link #delegateCaller};
46+
* <p>- in {@link #transactionBuilderDeployingDelegateCaller} we call {@link #entryPoint} with empty
47+
* call data which leads to the deployment of {@link #delegateCaller};
4648
*
47-
* <p>- in {@link #transactionLeadingDelegateCallerToCreateAnAccount} we call {@link #entryPoint}
48-
* with nonempty call data which leads it calling {@link #delegateCaller} which leads to it doing a
49-
* <b>DELEGATECALL</b> to {@link #simpleCreator} thus deploying a new account with {@link
50-
* #delegateCaller}'s nonce =1;
49+
* <p>- in {@link #transactionBuilderLeadingDelegateCallerToCreateAnAccount} we call {@link
50+
* #entryPoint} with nonempty call data which leads it calling {@link #delegateCaller} which leads
51+
* to it doing a <b>DELEGATECALL</b> to {@link #simpleCreator} thus deploying a new account with
52+
* {@link #delegateCaller}'s nonce =1;
5153
*
52-
* <p>- in {@link #transactionLeadingDelegateCallerToSelfDestruct} we call {@link #entryPoint} with
53-
* nonempty call data which leads it calling {@link #delegateCaller} which leads to it doing a
54-
* <b>DELEGATECALL</b> to {@link #simpleSelfDestructor} self destructing;
54+
* <p>- in {@link #transactionBuilderLeadingDelegateCallerToSelfDestruct} we call {@link
55+
* #entryPoint} with nonempty call data which leads it calling {@link #delegateCaller} which leads
56+
* to it doing a <b>DELEGATECALL</b> to {@link #simpleSelfDestructor} self destructing;
5557
*
56-
* <p>- in {@link #transactionDeployingDelegateCallerAgain} we call {@link #entryPoint} with empty
57-
* call data again which leads to the deployment of {@link #delegateCaller} <i>again</i>;
58+
* <p>- in {@link #transactionBuilderDeployingDelegateCallerAgain} we call {@link #entryPoint} with
59+
* empty call data again which leads to the deployment of {@link #delegateCaller} <i>again</i>;
5860
*
59-
* <p>- in {@link #transactionLeadingDelegateCallerToAttemptCreateAgainThusRaisingFailureConditionF}
60-
* we call {@link #entryPoint} with nonempty call data which leads it calling {@link
61-
* #delegateCaller} which leads to it doing a <b>DELEGATECALL</b> to {@link #simpleCreator} thus
62-
* <i>attempting</i> to redeploy at the same address where it did the first deployment; indeed
63-
* {@link #delegateCaller}'s nonce is again =1; deploying a new account at nonce 1;
61+
* <p>- in {@link
62+
* #transactionBuilderLeadingDelegateCallerToAttemptCreateAgainThusRaisingFailureConditionF} we call
63+
* {@link #entryPoint} with nonempty call data which leads it calling {@link #delegateCaller} which
64+
* leads to it doing a <b>DELEGATECALL</b> to {@link #simpleCreator} thus <i>attempting</i> to
65+
* redeploy at the same address where it did the first deployment; indeed {@link #delegateCaller}'s
66+
* nonce is again =1; deploying a new account at nonce 1;
6467
*/
6568
@ExtendWith(UnitTestWatcher.class)
6669
public class CreateInducedFailureTest {
@@ -201,67 +204,60 @@ public class CreateInducedFailureTest {
201204
.address(targetAddress)
202205
.build();
203206

204-
final Transaction transactionDeployingDelegateCaller =
207+
final ToyTransactionBuilder transactionBuilderDeployingDelegateCaller =
205208
ToyTransaction.builder()
206-
.sender(userAccount)
207209
.to(entryPoint)
208210
.keyPair(keyPair)
209211
.value(Wei.of(0xffff))
210212
.gasLimit(1_000_000L)
211-
.gasPrice(Wei.of(8))
212-
.build();
213+
.gasPrice(Wei.of(8));
213214

214-
final Transaction transactionLeadingDelegateCallerToCreateAnAccount =
215+
final ToyTransactionBuilder transactionBuilderLeadingDelegateCallerToCreateAnAccount =
215216
ToyTransaction.builder()
216-
.sender(userAccount.raiseNonceBy(1))
217217
.to(entryPoint)
218218
.keyPair(keyPair)
219219
.value(Wei.of(0xeeee))
220220
.gasLimit(1_000_000L)
221221
.gasPrice(Wei.of(8))
222-
.payload(leftPaddedAddress1)
223-
.build();
222+
.payload(leftPaddedAddress1);
224223

225-
final Transaction transactionLeadingDelegateCallerToSelfDestruct =
224+
final ToyTransactionBuilder transactionBuilderLeadingDelegateCallerToSelfDestruct =
226225
ToyTransaction.builder()
227-
.sender(userAccount.raiseNonceBy(2))
228226
.to(entryPoint)
229227
.keyPair(keyPair)
230228
.value(Wei.of(0xdddd))
231229
.gasLimit(1_000_000L)
232230
.gasPrice(Wei.of(8))
233-
.payload(leftPaddedAddress2)
234-
.build();
231+
.payload(leftPaddedAddress2);
235232

236-
final Transaction transactionDeployingDelegateCallerAgain =
233+
final ToyTransactionBuilder transactionBuilderDeployingDelegateCallerAgain =
237234
ToyTransaction.builder()
238-
.sender(userAccount.raiseNonceBy(3))
239235
.to(entryPoint)
240236
.keyPair(keyPair)
241237
.value(Wei.of(0xcccc))
242238
.gasLimit(1_000_000L)
243-
.gasPrice(Wei.of(8))
244-
.build();
239+
.gasPrice(Wei.of(8));
245240

246-
final Transaction
247-
transactionLeadingDelegateCallerToAttemptCreateAgainThusRaisingFailureConditionF =
241+
final ToyTransactionBuilder
242+
transactionBuilderLeadingDelegateCallerToAttemptCreateAgainThusRaisingFailureConditionF =
248243
ToyTransaction.builder()
249-
.sender(userAccount.raiseNonceBy(4))
250244
.to(entryPoint)
251245
.keyPair(keyPair)
252246
.value(Wei.of(0xbbbb))
253247
.gasLimit(1_000_000L)
254248
.gasPrice(Wei.of(8))
255-
.payload(leftPaddedAddress1)
256-
.build();
249+
.payload(leftPaddedAddress1);
250+
251+
final ToyTransactionBuilder[] toyTransactionBuilders = {
252+
transactionBuilderDeployingDelegateCaller,
253+
transactionBuilderLeadingDelegateCallerToCreateAnAccount,
254+
transactionBuilderLeadingDelegateCallerToSelfDestruct,
255+
transactionBuilderDeployingDelegateCallerAgain,
256+
transactionBuilderLeadingDelegateCallerToAttemptCreateAgainThusRaisingFailureConditionF
257+
};
257258

258259
final List<Transaction> transactions =
259-
List.of(
260-
transactionDeployingDelegateCaller,
261-
transactionLeadingDelegateCallerToCreateAnAccount,
262-
transactionLeadingDelegateCallerToSelfDestruct,
263-
transactionDeployingDelegateCallerAgain,
264-
transactionLeadingDelegateCallerToAttemptCreateAgainThusRaisingFailureConditionF);
260+
ToyMultiTransaction.builder().build(toyTransactionBuilders, userAccount);
265261

266262
final List<ToyAccount> accounts =
267263
List.of(userAccount, entryPoint, simpleSelfDestructor, simpleCreator);

tracer/testing/src/main/java/net/consensys/linea/testing/GeneralStateReferenceTestTools.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ public static void executeTest(
126126

127127
transactionProcessingResultValidator.accept(transaction, result);
128128
zkTracerValidator.accept(tracer);
129+
worldStateUpdater.commit();
129130
}
130131

131132
tracer.traceEndBlock(blockHeader, blockBody);
@@ -139,7 +140,6 @@ public static void executeTest(
139140
if (coinbase != null && coinbase.isEmpty() && shouldClearEmptyAccounts(spec.getFork())) {
140141
worldStateUpdater.deleteAccount(coinbase.getAddress());
141142
}
142-
worldStateUpdater.commit();
143143
worldState.persist(blockHeader);
144144

145145
// Check the world state root hash.

tracer/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,4 @@ public ReferenceTestWorldState.AccountMock toAccountMock() {
202202
return new ReferenceTestWorldState.AccountMock(
203203
Long.toHexString(nonce), balance.toHexString(), accountMockStorage, code.toHexString());
204204
}
205-
206-
public ToyAccount raiseNonceBy(long k) {
207-
long updatedNonce = this.getNonce() + k;
208-
return new ToyAccount(this.parent, this.getAddress(), updatedNonce, this.balance, this.balance);
209-
}
210205
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Consensys Software Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
16+
package net.consensys.linea.testing;
17+
18+
import java.util.ArrayList;
19+
import java.util.List;
20+
21+
import lombok.Builder;
22+
import net.consensys.linea.testing.ToyTransaction.ToyTransactionBuilder;
23+
import org.hyperledger.besu.ethereum.core.Transaction;
24+
25+
@Builder
26+
public class ToyMultiTransaction {
27+
28+
/** Customizations applied to the Lombok generated builder. */
29+
public static class ToyMultiTransactionBuilder {
30+
31+
/**
32+
* Builder method returning an instance of {@link List<Transaction>}.
33+
*
34+
* @return an instance of {@link List<Transaction>}
35+
*/
36+
public List<Transaction> build(
37+
ToyTransactionBuilder[] toyTxBuilders, ToyAccount senderAccount) {
38+
long senderAccountNonce = senderAccount.getNonce();
39+
List<Transaction> results = new ArrayList<>();
40+
for (ToyTransactionBuilder toyTxBuilder : toyTxBuilders) {
41+
results.add(toyTxBuilder.nonce(senderAccountNonce).build());
42+
senderAccountNonce++;
43+
}
44+
return results;
45+
}
46+
}
47+
}

tracer/testing/src/main/java/net/consensys/linea/testing/ToyTransaction.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import lombok.Builder;
2424
import org.apache.tuweni.bytes.Bytes;
2525
import org.hyperledger.besu.crypto.KeyPair;
26-
import org.hyperledger.besu.datatypes.AccessListEntry;
27-
import org.hyperledger.besu.datatypes.Address;
28-
import org.hyperledger.besu.datatypes.TransactionType;
29-
import org.hyperledger.besu.datatypes.Wei;
26+
import org.hyperledger.besu.datatypes.*;
3027
import org.hyperledger.besu.ethereum.core.Transaction;
3128

3229
@Builder

0 commit comments

Comments
 (0)