From 16548e98970e243c903535f8b24ef2efda88131a Mon Sep 17 00:00:00 2001 From: Gaurav Ahuja Date: Fri, 4 Oct 2024 12:29:14 +0530 Subject: [PATCH] Use coinbase address from block header for multi block tests (#1365) --- .../linea/zktracer}/ExampleMultiBlockTest.java | 6 +++++- .../net/consensys/linea/zktracer}/ExampleTxTest.java | 6 +++++- .../testing/MultiBlockExecutionEnvironment.java | 1 + .../linea/testing/ReplayExecutionEnvironment.java | 12 +++++++++--- 4 files changed, 20 insertions(+), 5 deletions(-) rename {testing/src/test/java/net/consensys/linea/testing => arithmetization/src/test/java/net/consensys/linea/zktracer}/ExampleMultiBlockTest.java (96%) rename {testing/src/test/java/net/consensys/linea/testing => arithmetization/src/test/java/net/consensys/linea/zktracer}/ExampleTxTest.java (89%) diff --git a/testing/src/test/java/net/consensys/linea/testing/ExampleMultiBlockTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java similarity index 96% rename from testing/src/test/java/net/consensys/linea/testing/ExampleMultiBlockTest.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java index 0dc94328a4..8cfbfff9e9 100644 --- a/testing/src/test/java/net/consensys/linea/testing/ExampleMultiBlockTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleMultiBlockTest.java @@ -13,10 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.testing; +package net.consensys.linea.zktracer; import java.util.List; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.MultiBlockExecutionEnvironment; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyTransaction; import net.consensys.linea.zktracer.opcode.OpCode; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; diff --git a/testing/src/test/java/net/consensys/linea/testing/ExampleTxTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleTxTest.java similarity index 89% rename from testing/src/test/java/net/consensys/linea/testing/ExampleTxTest.java rename to arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleTxTest.java index 9d67361098..3a84887d4d 100644 --- a/testing/src/test/java/net/consensys/linea/testing/ExampleTxTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ExampleTxTest.java @@ -13,10 +13,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.testing; +package net.consensys.linea.zktracer; import java.util.List; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironmentV2; +import net.consensys.linea.testing.ToyTransaction; import net.consensys.linea.zktracer.opcode.OpCode; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; diff --git a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java index 650a3e645b..4ca8130b41 100644 --- a/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java +++ b/testing/src/main/java/net/consensys/linea/testing/MultiBlockExecutionEnvironment.java @@ -54,6 +54,7 @@ public MultiBlockExecutionEnvironmentBuilder addBlock(List transact public void run() { ReplayExecutionEnvironment.builder() + .useCoinbaseAddressFromBlockHeader(true) .build() .replay(ToyExecutionEnvironmentV2.CHAIN_ID, this.buildConflationSnapshot()); } diff --git a/testing/src/main/java/net/consensys/linea/testing/ReplayExecutionEnvironment.java b/testing/src/main/java/net/consensys/linea/testing/ReplayExecutionEnvironment.java index 6f41b64fcf..ffdae20b32 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ReplayExecutionEnvironment.java +++ b/testing/src/main/java/net/consensys/linea/testing/ReplayExecutionEnvironment.java @@ -85,6 +85,8 @@ public class ReplayExecutionEnvironment { */ private final boolean txResultChecking; + @Builder.Default private final boolean useCoinbaseAddressFromBlockHeader = false; + private final ZkTracer zkTracer = new ZkTracer(); public void checkTracer(String inputFilePath) { @@ -155,7 +157,8 @@ private void executeFrom(final BigInteger chainId, final ConflationSnapshot conf tracer = ConflationAwareOperationTracer.sequence(tracer, capturer); } // Execute the conflation - executeFrom(chainId, conflation, tracer, this.txResultChecking); + executeFrom( + chainId, conflation, tracer, this.txResultChecking, this.useCoinbaseAddressFromBlockHeader); // if (debugBlockCapturer) { writeCaptureToFile(conflation, capturer); @@ -166,7 +169,8 @@ private static void executeFrom( final BigInteger chainId, final ConflationSnapshot conflation, final ConflationAwareOperationTracer tracer, - final boolean txResultChecking) { + final boolean txResultChecking, + final boolean useCoinbaseAddressFromBlockHeader) { BlockHashOperation.BlockHashLookup blockHashLookup = conflation.toBlockHashLookup(); // Initialise world state from conflation MutableWorldState world = initWorld(conflation); @@ -194,7 +198,9 @@ private static void executeFrom( updater, header, tx, - CliqueHelpers.getProposerOfBlock(header), + useCoinbaseAddressFromBlockHeader + ? header.getCoinbase() + : CliqueHelpers.getProposerOfBlock(header), buildOperationTracer(tx, txs.getOutcome(), tracer, txResultChecking), blockHashLookup, false,