From 522f6c97d969b5152cc72164f2d4da4dd5d377da Mon Sep 17 00:00:00 2001 From: Gaurav Ahuja Date: Fri, 16 Aug 2024 17:47:48 +0530 Subject: [PATCH] feat(toy-exec-env-v2): add new ToyExecutionEnvironment that builds the General State Test Case spec to run tests (#842) - migrate testing framework into new testing module and improve test execution logging - update besu version to 24.8-develop-dce796c - add gradle plugin to report test execution stats: status, duration for each executed test case Signed-off-by: Gaurav Ahuja Co-authored-by: Tsvetan Dimitrov --- .gitignore | 1 + arithmetization/build.gradle | 3 + .../consensys/linea/zktracer/ReplayTests.java | 2 +- .../linea/zktracer/module/add/AddTest.java | 4 +- .../linea/zktracer/module/bin/BinTest.java | 4 +- .../module/blockhash/BlockhashTest.java | 4 +- .../zktracer/module/ecdata/EcAddTest.java | 4 +- .../zktracer/module/ecdata/EcDataTest.java | 2 +- .../zktracer/module/ecdata/EcRecoverTest.java | 4 +- .../ecdata/ecpairing/EcPairingrTest.java | 4 +- .../linea/zktracer/module/exp/ExpTest.java | 5 +- .../module/ext/TestDuplicatedOperations.java | 4 +- .../module/hub/CallEmptyNoStopTest.java | 10 +- .../linea/zktracer/module/hub/OtherTests.java | 4 +- .../zktracer/module/hub/TestTwoPlusTwo.java | 4 +- .../zktracer/module/mmu/MemoryTests.java | 4 +- .../linea/zktracer/module/mod/ModTest.java | 4 +- .../zktracer/module/mod/ModTracerTest.java | 4 +- .../linea/zktracer/module/mxp/MxpTest.java | 20 +- .../zktracer/module/mxp/MxpTracerTest.java | 4 +- .../zktracer/module/oob/OobCallTest.java | 10 +- .../module/oob/OobJumpAndJumpiTest.java | 4 +- .../linea/zktracer/module/oob/OobRdcTest.java | 4 +- .../module/oob/OobSha2RipemdIdentityTest.java | 4 +- .../module/rlpaddr/TestRlpAddress.java | 10 +- .../module/rlptxrcpt/RandomTxrcptTests.java | 4 +- .../zktracer/module/shf/ShfRtTracerTest.java | 4 +- .../linea/zktracer/module/stp/StpTest.java | 10 +- .../zktracer/module/trm/TrmTracerTest.java | 4 +- .../zktracer/module/wcp/WcpEdgeCaseTest.java | 4 +- buildSrc/build.gradle | 2 +- .../src/main/groovy/common-plugins.gradle | 1 + gradle.properties | 2 +- gradle/tests.gradle | 49 +++++ .../GeneralStateReferenceTest.java.template | 4 +- settings.gradle | 2 + testing/build.gradle | 31 +++ .../linea}/testing/BytecodeCompiler.java | 2 +- .../linea}/testing/BytecodeRunner.java | 2 +- .../linea}/testing/DynamicTestCase.java | 2 +- .../linea}/testing/DynamicTests.java | 2 +- .../linea}/testing/ExampleTxTest.java | 2 +- .../GeneralStateReferenceTestTools.java | 180 ++++++++++++++++++ .../consensys/linea}/testing/ModuleTests.java | 2 +- .../consensys/linea}/testing/OpcodeCall.java | 2 +- .../consensys/linea}/testing/ToyAccount.java | 12 +- .../linea}/testing/ToyBlockValues.java | 2 +- .../testing/ToyExecutionEnvironment.java | 2 +- .../testing/ToyExecutionEnvironmentV2.java | 147 ++++++++++++++ .../linea}/testing/ToyTransaction.java | 2 +- .../consensys/linea}/testing/ToyWorld.java | 9 +- 51 files changed, 513 insertions(+), 99 deletions(-) create mode 100644 testing/build.gradle rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/BytecodeCompiler.java (99%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/BytecodeRunner.java (98%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/DynamicTestCase.java (96%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/DynamicTests.java (99%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ExampleTxTest.java (97%) create mode 100644 testing/src/main/java/net/consensys/linea/testing/GeneralStateReferenceTestTools.java rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ModuleTests.java (96%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/OpcodeCall.java (94%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ToyAccount.java (89%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ToyBlockValues.java (98%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ToyExecutionEnvironment.java (99%) create mode 100644 testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ToyTransaction.java (98%) rename {arithmetization/src/test/java/net/consensys/linea/zktracer => testing/src/main/java/net/consensys/linea}/testing/ToyWorld.java (95%) diff --git a/.gitignore b/.gitignore index 78819ac8fb..3aa3d826ca 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ nohup.out .externalToolBuilders/ .gradle/ .idea/ +.cargo/ .loadpath .metadata .prefs diff --git a/arithmetization/build.gradle b/arithmetization/build.gradle index abbab084db..4540a4200c 100644 --- a/arithmetization/build.gradle +++ b/arithmetization/build.gradle @@ -61,11 +61,14 @@ dependencies { implementation 'org.bouncycastle:bcprov-jdk18on' implementation 'org.hibernate.validator:hibernate-validator' + testImplementation project(path: ':testing') + testImplementation "${besuArtifactGroup}:evm" testImplementation "${besuArtifactGroup}:besu-datatypes" testImplementation "${besuArtifactGroup}.internal:core:${besuVersion}" testImplementation "${besuArtifactGroup}.internal:rlp:${besuVersion}" testImplementation "${besuArtifactGroup}.internal:core:${besuVersion}" + testImplementation "${besuArtifactGroup}.internal:referencetests:${besuVersion}" } configurations { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java index 774b35c66e..f1fc76277a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/ReplayTests.java @@ -24,7 +24,7 @@ import java.util.zip.GZIPInputStream; import lombok.extern.slf4j.Slf4j; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyExecutionEnvironment; import org.junit.jupiter.api.Test; /** diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/AddTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/AddTest.java index aca8ef628c..aef87adbb5 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/AddTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/add/AddTest.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.add; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java index b7bc806b79..fadee9e649 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/bin/BinTest.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.bin; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java index 1327774769..5d7a729937 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/blockhash/BlockhashTest.java @@ -17,9 +17,9 @@ import static net.consensys.linea.zktracer.module.constants.GlobalConstants.BLOCKHASH_MAX_HISTORY; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcAddTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcAddTest.java index 0252a489ea..6c4fe314e4 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcAddTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcAddTest.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.ecdata; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java index 63b23104f7..3e1f707435 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcDataTest.java @@ -15,7 +15,7 @@ package net.consensys.linea.zktracer.module.ecdata; -import net.consensys.linea.zktracer.testing.BytecodeRunner; +import net.consensys.linea.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java index afd5559f74..b5d686de75 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/EcRecoverTest.java @@ -23,9 +23,9 @@ import java.util.List; import java.util.stream.Stream; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/ecpairing/EcPairingrTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/ecpairing/EcPairingrTest.java index 9d35fe2f59..2018bca42a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/ecpairing/EcPairingrTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ecdata/ecpairing/EcPairingrTest.java @@ -34,9 +34,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/exp/ExpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/exp/ExpTest.java index 17c6dadff3..d51f130363 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/exp/ExpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/exp/ExpTest.java @@ -25,9 +25,9 @@ import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -234,6 +234,7 @@ private BytecodeCompiler initProgramInvokingModexp( } @Test + @Disabled void testExpUtils() { // ExpLog case log.debug("FFBlock"); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java index 9537c2ab6e..79c6099d7b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java @@ -17,9 +17,9 @@ import static org.assertj.core.api.Assertions.assertThat; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java index d19665cb31..304eca7947 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/CallEmptyNoStopTest.java @@ -19,12 +19,12 @@ import java.util.List; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import net.consensys.linea.zktracer.testing.ToyWorld; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java index 080270f421..0c3fb83527 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/OtherTests.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.hub; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.junit.jupiter.api.Test; public class OtherTests { diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java index 16d716b4cf..de1c9b4e72 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/hub/TestTwoPlusTwo.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.hub; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java index 99a8bbf0a4..220ecd426d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mmu/MemoryTests.java @@ -17,9 +17,9 @@ import java.util.Random; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java index 817993c5da..945c0d0ad6 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTest.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.mod; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java index ce0dc66952..f1889fb5be 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mod/ModTracerTest.java @@ -18,9 +18,9 @@ import java.util.List; import java.util.stream.Stream; +import net.consensys.linea.testing.DynamicTests; +import net.consensys.linea.testing.OpcodeCall; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.testing.DynamicTests; -import net.consensys.linea.zktracer.testing.OpcodeCall; import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.DynamicTest; import org.junit.jupiter.api.TestFactory; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java index b1546de473..e5cf5ab4c7 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTest.java @@ -23,14 +23,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironmentV2; +import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.opcode.gas.MxpType; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import net.consensys.linea.zktracer.testing.ToyWorld; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; @@ -250,7 +250,6 @@ void testCall() { Bytes.fromHexString( "0x1b4d679d0000000000000000000000003328358128832a260c76a4141e19e2a943cd4b6d0000000000000000000000005e17b14add6c386305a32928f985b29bba34eff5000000000000000000000000e2899bddfd890e320e643044c6b95b9b0b84157a000000000000000000000000d4fc541236927e2eaf8f27606bd7309c1fc2cbee0000000000000000000000005fd6eb55d12e759a21c09ef703fe0cba1dc9d88d")) .transactionType(TransactionType.FRONTIER) - .gasLimit(0xffffffffL) .value(Wei.ZERO) .keyPair(keyPair) .build(); @@ -268,12 +267,7 @@ void testCall() { contractMO2Account)) .build(); - ToyExecutionEnvironment.builder() - .toyWorld(toyWorld) - .transaction(tx) - .testValidator(x -> {}) - .build() - .run(); + ToyExecutionEnvironmentV2.builder().toyWorld(toyWorld).transaction(tx).build().run(); } // Support methods diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java index 24dc8297de..bb7d8ccc61 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/mxp/MxpTracerTest.java @@ -22,9 +22,9 @@ import java.util.List; import java.util.stream.Stream; +import net.consensys.linea.testing.DynamicTests; +import net.consensys.linea.testing.OpcodeCall; import net.consensys.linea.zktracer.module.Module; -import net.consensys.linea.zktracer.testing.DynamicTests; -import net.consensys.linea.zktracer.testing.OpcodeCall; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.DynamicTest; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java index 666ca1c925..40b0f32208 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobCallTest.java @@ -20,13 +20,13 @@ import java.math.BigInteger; import java.util.List; +import net.consensys.linea.testing.BytecodeRunner; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; -import net.consensys.linea.zktracer.testing.BytecodeRunner; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import net.consensys.linea.zktracer.testing.ToyWorld; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java index 4c05d59579..9093010355 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobJumpAndJumpiTest.java @@ -27,11 +27,11 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java index 3b39d8c1cc..c24ef18b45 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobRdcTest.java @@ -21,11 +21,11 @@ import java.math.BigInteger; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.module.hub.signals.Exceptions; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobSha2RipemdIdentityTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobSha2RipemdIdentityTest.java index 812888f3d9..e686853a9b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobSha2RipemdIdentityTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/oob/OobSha2RipemdIdentityTest.java @@ -24,10 +24,10 @@ import java.util.stream.IntStream; import com.google.common.io.BaseEncoding; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.module.hub.Hub; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.bouncycastle.crypto.digests.RIPEMD160Digest; import org.bouncycastle.util.encoders.Hex; import org.hyperledger.besu.datatypes.Address; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java index cadf940c54..0c6c8ad046 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlpaddr/TestRlpAddress.java @@ -25,12 +25,12 @@ import java.util.List; import java.util.Random; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import net.consensys.linea.zktracer.testing.ToyWorld; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java index 398bf29f8b..9a5f6ba09c 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/rlptxrcpt/RandomTxrcptTests.java @@ -22,8 +22,8 @@ import java.util.List; import java.util.Random; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyTransaction; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyTransaction; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.datatypes.AccessListEntry; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java index 56eadf8054..12878caee6 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/shf/ShfRtTracerTest.java @@ -19,9 +19,9 @@ import java.util.stream.Stream; import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Named; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java index 965798d688..664e43f87b 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/stp/StpTest.java @@ -24,12 +24,12 @@ import java.util.List; import java.util.Random; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.ToyAccount; +import net.consensys.linea.testing.ToyExecutionEnvironment; +import net.consensys.linea.testing.ToyTransaction; +import net.consensys.linea.testing.ToyWorld; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.ToyAccount; -import net.consensys.linea.zktracer.testing.ToyExecutionEnvironment; -import net.consensys.linea.zktracer.testing.ToyTransaction; -import net.consensys.linea.zktracer.testing.ToyWorld; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.crypto.KeyPair; import org.hyperledger.besu.crypto.SECP256K1; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java index 0515dd860f..324fd9648a 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/trm/TrmTracerTest.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.trm; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpEdgeCaseTest.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpEdgeCaseTest.java index 2ec181875f..a643641ca5 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpEdgeCaseTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpEdgeCaseTest.java @@ -15,9 +15,9 @@ package net.consensys.linea.zktracer.module.wcp; +import net.consensys.linea.testing.BytecodeCompiler; +import net.consensys.linea.testing.BytecodeRunner; import net.consensys.linea.zktracer.opcode.OpCode; -import net.consensys.linea.zktracer.testing.BytecodeCompiler; -import net.consensys.linea.zktracer.testing.BytecodeRunner; import org.apache.tuweni.bytes.Bytes; import org.junit.jupiter.api.Test; diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 0d3ae50043..ae3b28bd7b 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -28,5 +28,5 @@ dependencies { implementation 'com.github.hierynomus.license:com.github.hierynomus.license.gradle.plugin:0.16.1' implementation 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.5' implementation 'de.undercouch.download:de.undercouch.download.gradle.plugin:5.6.0' + implementation 'com.adarshr:gradle-test-logger-plugin:4.0.0' } - diff --git a/buildSrc/src/main/groovy/common-plugins.gradle b/buildSrc/src/main/groovy/common-plugins.gradle index c281ea63a5..302ac78d85 100644 --- a/buildSrc/src/main/groovy/common-plugins.gradle +++ b/buildSrc/src/main/groovy/common-plugins.gradle @@ -19,4 +19,5 @@ plugins { id 'com.github.ben-manes.versions' id 'io.spring.dependency-management' id "de.undercouch.download" + id 'com.adarshr.test-logger' } diff --git a/gradle.properties b/gradle.properties index 233b0e0966..1dfe22c73f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ releaseVersion=0.3.0-rc2 -besuVersion=24.7-develop-c0029e6 +besuVersion=24.8-develop-dce796c besuArtifactGroup=io.consensys.linea-besu distributionIdentifier=linea-tracer distributionBaseUrl=https://artifacts.consensys.net/public/linea-besu/raw/names/linea-besu.tar.gz/versions/ diff --git a/gradle/tests.gradle b/gradle/tests.gradle index 4778741245..c230351d9b 100644 --- a/gradle/tests.gradle +++ b/gradle/tests.gradle @@ -20,6 +20,8 @@ jacoco { toolVersion = '0.8.12' } +apply plugin: 'com.adarshr.test-logger' + /* * Pass some system properties provided on the gradle command line to test executions for * convenience. @@ -61,6 +63,53 @@ test { } } + testlogger { + // pick a theme - mocha, standard, plain, mocha-parallel, standard-parallel or plain-parallel + theme 'standard' + + // set to false to disable detailed failure logs + showExceptions true + + // set to false to hide stack traces + showStackTraces true + + // set to true to remove any filtering applied to stack traces + showFullStackTraces false + + // set to false to hide exception causes + showCauses true + + // set threshold in milliseconds to highlight slow tests + slowThreshold 2000 + + // displays a breakdown of passes, failures and skips along with total duration + showSummary true + + // set to true to see simple class names + showSimpleNames false + + // set to false to hide passed tests + showPassed true + + // set to false to hide skipped tests + showSkipped true + + // set to false to hide failed tests + showFailed true + + // enable to see standard out and error streams inline with the test results + showStandardStreams false + + // set to false to hide passed standard out and error streams + showPassedStandardStreams true + + // set to false to hide skipped standard out and error streams + showSkippedStandardStreams true + + // set to false to hide failed standard out and error streams + showFailedStandardStreams true + } + useJUnitPlatform() } diff --git a/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template b/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template index b34d0f7b4d..53a0455564 100644 --- a/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template +++ b/reference-tests/src/test/resources/templates/GeneralStateReferenceTest.java.template @@ -15,8 +15,8 @@ package net.consensys.linea.generated.generalstate; -import static net.consensys.linea.GeneralStateReferenceTestTools.executeTest; -import static net.consensys.linea.GeneralStateReferenceTestTools.generateTestParametersForConfig; +import static net.consensys.linea.testing.GeneralStateReferenceTestTools.executeTest; +import static net.consensys.linea.testing.GeneralStateReferenceTestTools.generateTestParametersForConfig; import static org.junit.jupiter.api.Assumptions.assumeTrue; import java.util.stream.Stream; diff --git a/settings.gradle b/settings.gradle index 40900f20f8..349af214e8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -25,3 +25,5 @@ rootProject.name = 'linea-arithmetization' include 'arithmetization' include 'reference-tests' +include 'testing' + diff --git a/testing/build.gradle b/testing/build.gradle new file mode 100644 index 0000000000..9fc75966ca --- /dev/null +++ b/testing/build.gradle @@ -0,0 +1,31 @@ +plugins { + id "common-plugins" +} + +apply from: rootProject.file("gradle/corset.gradle") +apply from: rootProject.file("gradle/java.gradle") +apply from: rootProject.file("gradle/tests.gradle") +apply from: rootProject.file("gradle/dependency-management.gradle") +apply from: rootProject.file('gradle/common-dependencies.gradle') +apply from: rootProject.file("gradle/lint.gradle") + +dependencies { + implementation project(path: ':arithmetization') + implementation "${besuArtifactGroup}:besu-datatypes" + implementation "${besuArtifactGroup}:evm" + implementation "${besuArtifactGroup}.internal:core:${besuVersion}" + implementation "${besuArtifactGroup}.internal:referencetests:${besuVersion}" + implementation "${besuArtifactGroup}.internal:rlp:${besuVersion}" + implementation "${besuArtifactGroup}.internal:testutil:${besuVersion}" + implementation "${besuArtifactGroup}.internal:algorithms:${besuVersion}" + implementation "${besuArtifactGroup}:plugin-api" + + implementation 'org.junit.jupiter:junit-jupiter-api' + runtimeOnly 'org.junit.jupiter:junit-jupiter-engine' + implementation 'org.junit.jupiter:junit-jupiter-params' + runtimeOnly 'org.junit.vintage:junit-vintage-engine' + + implementation 'org.mockito:mockito-core' + implementation 'org.mockito:mockito-junit-jupiter' + implementation 'org.assertj:assertj-core' +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java b/testing/src/main/java/net/consensys/linea/testing/BytecodeCompiler.java similarity index 99% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java rename to testing/src/main/java/net/consensys/linea/testing/BytecodeCompiler.java index eb6e4baab4..3cb49a4ea5 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeCompiler.java +++ b/testing/src/main/java/net/consensys/linea/testing/BytecodeCompiler.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import static net.consensys.linea.zktracer.types.Conversions.bigIntegerToBytes; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java b/testing/src/main/java/net/consensys/linea/testing/BytecodeRunner.java similarity index 98% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java rename to testing/src/main/java/net/consensys/linea/testing/BytecodeRunner.java index 22532c91e9..b9dab32f6d 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/BytecodeRunner.java +++ b/testing/src/main/java/net/consensys/linea/testing/BytecodeRunner.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.List; import java.util.Optional; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.java b/testing/src/main/java/net/consensys/linea/testing/DynamicTestCase.java similarity index 96% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.java rename to testing/src/main/java/net/consensys/linea/testing/DynamicTestCase.java index 2202041a20..549100b243 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTestCase.java +++ b/testing/src/main/java/net/consensys/linea/testing/DynamicTestCase.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.List; import java.util.function.BiConsumer; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java b/testing/src/main/java/net/consensys/linea/testing/DynamicTests.java similarity index 99% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java rename to testing/src/main/java/net/consensys/linea/testing/DynamicTests.java index ee09c2353c..a6e16c65bc 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/DynamicTests.java +++ b/testing/src/main/java/net/consensys/linea/testing/DynamicTests.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.ArrayList; import java.util.LinkedList; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java b/testing/src/main/java/net/consensys/linea/testing/ExampleTxTest.java similarity index 97% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java rename to testing/src/main/java/net/consensys/linea/testing/ExampleTxTest.java index 3269537c0c..f37852bff9 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ExampleTxTest.java +++ b/testing/src/main/java/net/consensys/linea/testing/ExampleTxTest.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.List; diff --git a/testing/src/main/java/net/consensys/linea/testing/GeneralStateReferenceTestTools.java b/testing/src/main/java/net/consensys/linea/testing/GeneralStateReferenceTestTools.java new file mode 100644 index 0000000000..776eb64d4f --- /dev/null +++ b/testing/src/main/java/net/consensys/linea/testing/GeneralStateReferenceTestTools.java @@ -0,0 +1,180 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.testing; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.corset.CorsetValidator; +import net.consensys.linea.zktracer.ZkTracer; +import org.hyperledger.besu.datatypes.BlobGas; +import org.hyperledger.besu.datatypes.Hash; +import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.core.*; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; +import org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams; +import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; +import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; +import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseEipSpec; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestBlockchain; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState; +import org.hyperledger.besu.ethereum.rlp.RLP; +import org.hyperledger.besu.ethereum.vm.CachingBlockHashLookup; +import org.hyperledger.besu.evm.account.Account; +import org.hyperledger.besu.evm.log.Log; +import org.hyperledger.besu.evm.worldstate.WorldUpdater; + +@Slf4j +public class GeneralStateReferenceTestTools { + private static final List SPECS_PRIOR_TO_DELETING_EMPTY_ACCOUNTS = + Arrays.asList("Frontier", "Homestead", "EIP150"); + private static final CorsetValidator CORSET_VALIDATOR = new CorsetValidator(); + + private GeneralStateReferenceTestTools() { + // utility class + } + + @SneakyThrows + public static void executeTest( + final GeneralStateTestCaseEipSpec spec, + final MainnetTransactionProcessor processor, + final FeeMarket feeMarket) { + final BlockHeader blockHeader = spec.getBlockHeader(); + final ReferenceTestWorldState initialWorldState = spec.getInitialWorldState(); + final List transactions = new ArrayList<>(); + for (int i = 0; i < spec.getTransactionsCount(); i++) { + Transaction transaction = spec.getTransaction(i); + + // Sometimes the tests ask us assemble an invalid transaction. If we have + // no valid transaction then there is no test. GeneralBlockChain tests + // will handle the case where we receive the TXs in a serialized form. + if (transaction == null) { + assertThat(spec.getExpectException()) + .withFailMessage("Transaction was not assembled, but no exception was expected") + .isNotNull(); + return; + } + + transactions.add(transaction); + } + + final BlockBody blockBody = new BlockBody(transactions, new ArrayList<>()); + final MutableWorldState worldState = initialWorldState; + // final MutableWorldState worldState = initialWorldState.copy(); + final WorldUpdater worldStateUpdater = worldState.updater(); + final ReferenceTestBlockchain blockchain = new ReferenceTestBlockchain(blockHeader.getNumber()); + final Wei blobGasPrice = + feeMarket.blobGasPricePerGas(blockHeader.getExcessBlobGas().orElse(BlobGas.ZERO)); + + final ZkTracer tracer = new ZkTracer(); + + tracer.traceStartConflation(1); + tracer.traceStartBlock(blockHeader, blockBody); + TransactionProcessingResult result = null; + for (Transaction transaction : blockBody.getTransactions()) { + // Several of the GeneralStateTests check if the transaction could potentially + // consume more gas than is left for the block it's attempted to be included in. + // This check is performed within the `BlockImporter` rather than inside the + // `TransactionProcessor`, so these tests are skipped. + if (transaction.getGasLimit() > blockHeader.getGasLimit() - blockHeader.getGasUsed()) { + throw new IllegalArgumentException("Transaction gas limit higher that avaliable in block"); + } + + result = + processor.processTransaction( + worldStateUpdater, + blockHeader, + transaction, + blockHeader.getCoinbase(), + tracer, + new CachingBlockHashLookup(blockHeader, blockchain), + false, + TransactionValidationParams.processingBlock(), + blobGasPrice); + + if (result.isInvalid()) { + final TransactionProcessingResult finalResult = result; + assertThat(spec.getExpectException()) + .withFailMessage(() -> finalResult.getValidationResult().getErrorMessage()) + .isNotNull(); + return; + } + } + + tracer.traceEndBlock(blockHeader, blockBody); + tracer.traceEndConflation(worldStateUpdater); + + assertThat(spec.getExpectException()) + .withFailMessage("Exception was expected - " + spec.getExpectException()) + .isNull(); + + final Account coinbase = worldStateUpdater.getOrCreate(spec.getBlockHeader().getCoinbase()); + if (coinbase != null && coinbase.isEmpty() && shouldClearEmptyAccounts(spec.getFork())) { + worldStateUpdater.deleteAccount(coinbase.getAddress()); + } + worldStateUpdater.commit(); + worldState.persist(blockHeader); + + // Check the world state root hash. + final Hash expectedRootHash = spec.getExpectedRootHash(); + Optional.ofNullable(expectedRootHash) + .ifPresent( + expected -> { + assertThat(worldState.rootHash()) + .withFailMessage( + "Unexpected world state root hash; expected state: %s, computed state: %s", + spec.getExpectedRootHash(), worldState.rootHash()) + .isEqualTo(expected); + }); + + // Check the logs. + final Hash expectedLogsHash = spec.getExpectedLogsHash(); + final TransactionProcessingResult finalResult = result; + Optional.ofNullable(expectedLogsHash) + .ifPresent( + expected -> { + assert finalResult != null; + final List logs = finalResult.getLogs(); + + assertThat(Hash.hash(RLP.encode(out -> out.writeList(logs, Log::writeTo)))) + .withFailMessage("Unmatched logs hash. Generated logs: %s", logs) + .isEqualTo(expected); + }); + + try { + final Path traceFile = Files.createTempFile(null, ".lt"); + tracer.writeToFile(traceFile); + log.info("trace written to `{}`", traceFile); + assertThat(CORSET_VALIDATOR.validate(traceFile).isValid()).isTrue(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static boolean shouldClearEmptyAccounts(final String eip) { + return !SPECS_PRIOR_TO_DELETING_EMPTY_ACCOUNTS.contains(eip); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java b/testing/src/main/java/net/consensys/linea/testing/ModuleTests.java similarity index 96% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java rename to testing/src/main/java/net/consensys/linea/testing/ModuleTests.java index 5c73bc096e..21f71bb344 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ModuleTests.java +++ b/testing/src/main/java/net/consensys/linea/testing/ModuleTests.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.List; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java b/testing/src/main/java/net/consensys/linea/testing/OpcodeCall.java similarity index 94% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java rename to testing/src/main/java/net/consensys/linea/testing/OpcodeCall.java index 0be8754671..35e8fc5dd3 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/OpcodeCall.java +++ b/testing/src/main/java/net/consensys/linea/testing/OpcodeCall.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.List; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java similarity index 89% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java rename to testing/src/main/java/net/consensys/linea/testing/ToyAccount.java index 4dcf2480e5..8ab6fe8646 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyAccount.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyAccount.java @@ -14,7 +14,7 @@ * */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.HashMap; import java.util.Map; @@ -30,6 +30,7 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState; import org.hyperledger.besu.evm.ModificationNotAllowedException; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.AccountStorageEntry; @@ -174,4 +175,13 @@ public Map getUpdatedStorage() { public void becomeImmutable() { mutable = false; } + + public ReferenceTestWorldState.AccountMock toAccountMock() { + Map accountMockStorage = new HashMap<>(); + for (Map.Entry e : storage.entrySet()) { + accountMockStorage.put(e.getKey().toHexString(), e.getValue().toHexString()); + } + return new ReferenceTestWorldState.AccountMock( + Long.toHexString(nonce), balance.toHexString(), accountMockStorage, code.toHexString()); + } } diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java b/testing/src/main/java/net/consensys/linea/testing/ToyBlockValues.java similarity index 98% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java rename to testing/src/main/java/net/consensys/linea/testing/ToyBlockValues.java index e4bfc7d4b9..12343c71b0 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyBlockValues.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyBlockValues.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_BASE_FEE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_BLOCK_GAS_LIMIT; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironment.java similarity index 99% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java rename to testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironment.java index 204ca6122d..558047aa9e 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyExecutionEnvironment.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironment.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_BASE_FEE; import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_BLOCK_GAS_LIMIT; diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java new file mode 100644 index 0000000000..e2e767a0c9 --- /dev/null +++ b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java @@ -0,0 +1,147 @@ +/* + * Copyright Consensys Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +package net.consensys.linea.testing; + +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_BASE_FEE; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_BLOCK_GAS_LIMIT; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LINEA_DIFFICULTY; +import static net.consensys.linea.zktracer.runtime.stack.Stack.MAX_STACK_SIZE; + +import java.math.BigInteger; +import java.util.*; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +import lombok.Builder; +import lombok.Singular; +import lombok.extern.slf4j.Slf4j; +import net.consensys.linea.zktracer.ZkTracer; +import net.consensys.linea.zktracer.module.constants.GlobalConstants; +import org.hyperledger.besu.datatypes.*; +import org.hyperledger.besu.ethereum.core.*; +import org.hyperledger.besu.ethereum.core.Transaction; +import org.hyperledger.besu.ethereum.core.feemarket.CoinbaseFeePriceCalculator; +import org.hyperledger.besu.ethereum.mainnet.LondonTargetingGasLimitCalculator; +import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; +import org.hyperledger.besu.ethereum.mainnet.TransactionValidatorFactory; +import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; +import org.hyperledger.besu.ethereum.mainnet.feemarket.LondonFeeMarket; +import org.hyperledger.besu.ethereum.referencetests.GeneralStateTestCaseEipSpec; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestWorldState; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; +import org.hyperledger.besu.evm.gascalculator.GasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; +import org.hyperledger.besu.evm.precompile.MainnetPrecompiledContracts; +import org.hyperledger.besu.evm.precompile.PrecompileContractRegistry; +import org.hyperledger.besu.evm.processor.ContractCreationProcessor; +import org.hyperledger.besu.evm.processor.MessageCallProcessor; + +@Builder +@Slf4j +public class ToyExecutionEnvironmentV2 { + public static final BigInteger CHAIN_ID = BigInteger.valueOf(1337); + + private static final Wei DEFAULT_BASE_FEE = Wei.of(LINEA_BASE_FEE); + + private static final GasCalculator gasCalculator = ZkTracer.gasCalculator; + private static final Address minerAddress = Address.fromHexString("0x1234532342"); + private static final long DEFAULT_BLOCK_NUMBER = 6678980; + private static final long DEFAULT_TIME_STAMP = 1347310; + private static final Hash DEFAULT_HASH = + Hash.fromHexStringLenient("0xdeadbeef123123666dead666dead666"); + private static final EVM evm = MainnetEVMs.london(EvmConfiguration.DEFAULT); + private static final FeeMarket feeMarket = FeeMarket.london(-1); + + @Builder.Default private BigInteger chainId = CHAIN_ID; + private final ToyWorld toyWorld; + @Singular private final List transactions; + + public void run() { + GeneralStateReferenceTestTools.executeTest( + this.buildGeneralStateTestCaseSpec(), getMainnetTransactionProcessor(), feeMarket); + } + + public GeneralStateTestCaseEipSpec buildGeneralStateTestCaseSpec() { + Map accountMockMap = + toyWorld.getAddressAccountMap().entrySet().stream() + .collect( + Collectors.toMap( + entry -> entry.getKey().toHexString(), + entry -> entry.getValue().toAccountMock())); + ReferenceTestWorldState referenceTestWorldState = + ReferenceTestWorldState.create(accountMockMap, evm.getEvmConfiguration()); + BlockHeader blockHeader = + BlockHeaderBuilder.createDefault() + .baseFee(DEFAULT_BASE_FEE) + .gasLimit(LINEA_BLOCK_GAS_LIMIT) + .difficulty(Difficulty.of(LINEA_DIFFICULTY)) + .number(DEFAULT_BLOCK_NUMBER) + .coinbase(minerAddress) + .timestamp(DEFAULT_TIME_STAMP) + .parentHash(DEFAULT_HASH) + .buildBlockHeader(); + + List> txSuppliers = new ArrayList<>(); + for (Transaction tx : transactions) { + txSuppliers.add(() -> tx); + } + + return new GeneralStateTestCaseEipSpec( + /*fork*/ evm.getEvmVersion().getName().toLowerCase(), + txSuppliers, + referenceTestWorldState, + /*expectedRootHash*/ null, + /*expectedLogsHash*/ null, + blockHeader, + /*dataIndex*/ -1, + /*gasIndex*/ -1, + /*valueIndex*/ -1, + /*expectException*/ null); + } + + private MainnetTransactionProcessor getMainnetTransactionProcessor() { + + PrecompileContractRegistry precompileContractRegistry = new PrecompileContractRegistry(); + + MainnetPrecompiledContracts.populateForIstanbul( + precompileContractRegistry, evm.getGasCalculator()); + + final MessageCallProcessor messageCallProcessor = + new MessageCallProcessor(evm, precompileContractRegistry); + + final ContractCreationProcessor contractCreationProcessor = + new ContractCreationProcessor(evm, false, List.of(), 0); + + return new MainnetTransactionProcessor( + gasCalculator, + new TransactionValidatorFactory( + gasCalculator, + new LondonTargetingGasLimitCalculator(0L, new LondonFeeMarket(0)), + new LondonFeeMarket(0L), + false, + Optional.of(this.chainId), + Set.of(TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559), + GlobalConstants.MAX_CODE_SIZE), + contractCreationProcessor, + messageCallProcessor, + true, + true, + MAX_STACK_SIZE, + feeMarket, + CoinbaseFeePriceCalculator.eip1559()); + } +} diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java b/testing/src/main/java/net/consensys/linea/testing/ToyTransaction.java similarity index 98% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java rename to testing/src/main/java/net/consensys/linea/testing/ToyTransaction.java index 8dfe6965df..f045e236c7 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyTransaction.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyTransaction.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.math.BigInteger; import java.util.ArrayList; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java b/testing/src/main/java/net/consensys/linea/testing/ToyWorld.java similarity index 95% rename from arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java rename to testing/src/main/java/net/consensys/linea/testing/ToyWorld.java index fcfa88aebb..1b53dad8cd 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/testing/ToyWorld.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyWorld.java @@ -13,7 +13,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.testing; +package net.consensys.linea.testing; import java.util.ArrayList; import java.util.Collection; @@ -41,8 +41,8 @@ public class ToyWorld implements WorldUpdater { private ToyWorld parent; @Getter private List accounts; - private Map addressAccountMap; private AuthorizedCodeService authorizedCodeService; + @Getter private Map addressAccountMap; private ToyWorld() { this(null, new ArrayList<>()); @@ -186,11 +186,6 @@ public Optional parentUpdater() { return Optional.empty(); } - @Override - public void setAuthorizedCodeService(final AuthorizedCodeService authorizedCodeService) { - this.authorizedCodeService = authorizedCodeService; - } - public static class ToyWorldBuilder { public ToyWorld build() { ToyWorld toyWorld = new ToyWorld(parent);