diff --git a/build.gradle b/build.gradle index 09dd4c0f35..8a70608865 100644 --- a/build.gradle +++ b/build.gradle @@ -215,6 +215,18 @@ allprojects { useJUnitPlatform() } + task unitTests(type: Test) { + useJUnitPlatform { + excludeTags("CorsetTest") + } + } + + task corsetTests(type: Test) { + useJUnitPlatform { + includeTags("CorsetTest") + } + } + javadoc { options.addStringOption('Xdoclint:all', '-quiet') options.addStringOption('Xwerror', '-html5') diff --git a/src/main/java/net/consensys/linea/zktracer/module/Util.java b/src/main/java/net/consensys/linea/zktracer/module/Util.java index 37d41173ca..f97153ff01 100644 --- a/src/main/java/net/consensys/linea/zktracer/module/Util.java +++ b/src/main/java/net/consensys/linea/zktracer/module/Util.java @@ -119,7 +119,7 @@ public static UInt256 multiplyRange(Bytes[] range1, Bytes[] range2) { UInt256 sum = UInt256.ZERO; for (int i = 0; i < range1.length; i++) { UInt256 prod = - UInt256.fromBytes(range1[i]).multiply(UInt256.fromBytes(range2[range2.length - i - 1])); + UInt256.fromBytes(range1[i]).multiply(UInt256.fromBytes(range2[range2.length - i - 1])); sum = sum.add(prod); } return sum; diff --git a/src/main/java/net/consensys/linea/zktracer/module/alu/mul/MulData.java b/src/main/java/net/consensys/linea/zktracer/module/alu/mul/MulData.java index 847c6fb215..d512c0264a 100644 --- a/src/main/java/net/consensys/linea/zktracer/module/alu/mul/MulData.java +++ b/src/main/java/net/consensys/linea/zktracer/module/alu/mul/MulData.java @@ -1,3 +1,17 @@ +/* + * Copyright ConsenSys AG. + * + * 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.zktracer.module.alu.mul; import static net.consensys.linea.zktracer.module.Util.boolToByte; diff --git a/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java b/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java index 3a1ae8bae0..913fd42d91 100644 --- a/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java +++ b/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java @@ -20,6 +20,7 @@ import java.util.stream.Stream; import org.apache.tuweni.bytes.Bytes32; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; import org.junit.jupiter.params.ParameterizedTest; @@ -27,6 +28,7 @@ import org.junit.jupiter.params.provider.MethodSource; @TestInstance(Lifecycle.PER_CLASS) +@Tag("CorsetTest") public abstract class AbstractModuleTracerCorsetTest extends AbstractBaseModuleTracerTest { static final Random rand = new Random(); private static final int TEST_REPETITIONS = 8; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java b/src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java index 3744d0623f..066b66eaf4 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java @@ -22,7 +22,6 @@ import net.consensys.linea.zktracer.AbstractModuleTracerCorsetTest; import net.consensys.linea.zktracer.OpCode; import net.consensys.linea.zktracer.module.ModuleTracer; -import net.consensys.linea.zktracer.module.alu.add.AddTracer; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java b/src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java index b0cae0758a..590c74bb96 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java @@ -18,7 +18,6 @@ import net.consensys.linea.zktracer.OpCode; import net.consensys.linea.zktracer.bytestheta.BaseBytes; -import net.consensys.linea.zktracer.module.alu.add.Adder; import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.Test; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/ext/ExtTracerTest.java b/src/test/java/net/consensys/linea/zktracer/module/alu/ext/ExtTracerTest.java index 0f174d6dba..8170e01673 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/ext/ExtTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/alu/ext/ExtTracerTest.java @@ -22,7 +22,6 @@ import net.consensys.linea.zktracer.AbstractModuleTracerCorsetTest; import net.consensys.linea.zktracer.OpCode; import net.consensys.linea.zktracer.module.ModuleTracer; -import net.consensys.linea.zktracer.module.alu.ext.ExtTracer; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; import org.junit.jupiter.api.Assertions; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/mod/ModTracerTest.java b/src/test/java/net/consensys/linea/zktracer/module/alu/mod/ModTracerTest.java index 5da8d66b99..b046a13bf5 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/mod/ModTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/alu/mod/ModTracerTest.java @@ -23,7 +23,6 @@ import net.consensys.linea.zktracer.AbstractModuleTracerCorsetTest; import net.consensys.linea.zktracer.OpCode; import net.consensys.linea.zktracer.module.ModuleTracer; -import net.consensys.linea.zktracer.module.alu.mod.ModTracer; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.units.bigints.UInt256; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/mul/MulUtilsTest.java b/src/test/java/net/consensys/linea/zktracer/module/alu/mul/MulUtilsTest.java index 702c646c62..2671110630 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/mul/MulUtilsTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/alu/mul/MulUtilsTest.java @@ -1,3 +1,17 @@ +/* + * Copyright ConsenSys AG. + * + * 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.zktracer.module.alu.mul; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; diff --git a/src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java b/src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java index 1d3609fa83..5b24a645b0 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java @@ -32,6 +32,7 @@ import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Named; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -43,6 +44,7 @@ import org.slf4j.LoggerFactory; @ExtendWith(MockitoExtension.class) +@Tag("CorsetTest") class ShfTracerTest { private static final Logger LOG = LoggerFactory.getLogger(ShfTracerTest.class); diff --git a/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java b/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java index 337c95daae..3a3e78c1aa 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java @@ -14,87 +14,32 @@ */ package net.consensys.linea.zktracer.module.wcp; -import static net.consensys.linea.zktracer.OpCode.SGT; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.mockito.Mockito.when; +import static net.consensys.linea.zktracer.OpCode.GT; -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; - -import java.util.ArrayList; import java.util.List; -import java.util.Random; import java.util.stream.Stream; -import net.consensys.linea.zktracer.OpCode; -import net.consensys.linea.zktracer.ZkTraceBuilder; -import net.consensys.linea.zktracer.ZkTracer; -import net.consensys.linea.zktracer.corset.CorsetValidator; -import net.consensys.linea.zktracer.module.wcp.WcpTracer; +import net.consensys.linea.zktracer.AbstractModuleTracerCorsetTest; +import net.consensys.linea.zktracer.module.ModuleTracer; import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class WcpTracerTest { - private ZkTracer zkTracer; - private ZkTraceBuilder zkTraceBuilder; - @Mock MessageFrame mockFrame; - @Mock Operation mockOperation; - - private static final Random rand = new Random(); - private static final int TEST_REPETITIONS = 4; - - @BeforeEach - void setUp() { - zkTraceBuilder = new ZkTraceBuilder(); - zkTracer = new ZkTracer(zkTraceBuilder, List.of(new WcpTracer())); - when(mockFrame.getCurrentOperation()).thenReturn(mockOperation); - } +class WcpTracerTest extends AbstractModuleTracerCorsetTest { - @ParameterizedTest() - @MethodSource("provideRandomArguments") - void testRandomWcp(OpCode opCode, final Bytes32 arg1, Bytes32 arg2) { - when(mockOperation.getOpcode()).thenReturn((int) opCode.value); - when(mockFrame.getStackItem(0)).thenReturn(arg1); - when(mockFrame.getStackItem(1)).thenReturn(arg2); - zkTracer.tracePreExecution(mockFrame); - assertThat(CorsetValidator.isValid(zkTraceBuilder.build().toJson())).isTrue(); + @Override + protected ModuleTracer getModuleTracer() { + return new WcpTracer(); } - @Test - public void testNonRandomWcp() { + @Override + protected Stream provideNonRandomArguments() { Bytes32 arg1 = Bytes32.fromHexString("0xdcd5cf52e4daec5389587d0d0e996e6ce2d0546b63d3ea0a0dc48ad984d180a9"); Bytes32 arg2 = Bytes32.fromHexString("0x0479484af4a59464a48818b3980174687661bafb13d06f49537995fa6c02159e"); - traceOperation(SGT, arg1, arg2); - } - - public static Stream provideRandomArguments() { - final List arguments = new ArrayList<>(); - for (OpCode opCode : new WcpTracer().supportedOpCodes()) { - for (int i = 0; i <= TEST_REPETITIONS; i++) { - Bytes32[] payload = new Bytes32[2]; - payload[0] = Bytes32.random(rand); - payload[1] = Bytes32.random(rand); - arguments.add(Arguments.of(opCode, payload[0], payload[1])); - } - } - return arguments.stream(); - } - - private void traceOperation(OpCode opcode, Bytes32 arg1, Bytes32 arg2) { - when(mockOperation.getOpcode()).thenReturn((int) opcode.value); - when(mockFrame.getStackItem(0)).thenReturn(arg1); - when(mockFrame.getStackItem(1)).thenReturn(arg2); - zkTracer.tracePreExecution(mockFrame); - assertThat(CorsetValidator.isValid(zkTraceBuilder.build().toJson())).isTrue(); + return Stream.of(Arguments.of(GT, List.of(arg1, arg2))); } }