From cdb9672721837fa41a2db7f5fd381a4d0a44c735 Mon Sep 17 00:00:00 2001 From: Gabriel-Trintinalia Date: Mon, 24 Apr 2023 15:47:33 +1000 Subject: [PATCH] Implement test by file --- build.gradle | 4 +- .../AbstractBaseModuleTracerTest.java | 66 +++++++++++ .../AbstractModuleTracerBySpecTest.java | 110 ++++++++++++++++++ ...va => AbstractModuleTracerCorsetTest.java} | 42 +------ .../corset}/CorsetValidator.java | 2 +- .../module/alu/add/AddTracerTest.java | 7 +- .../module/alu/add/AdderTest.java | 3 +- .../module/alu/mod/ModTracerTest.java | 7 +- .../module/shf/ShfTracerTest.java | 5 +- .../module/wcp/WcpTracerTest.java | 5 +- .../zktracer/specs/ModTracerBySpecTest.java | 33 ++++++ .../zktracer/mod/trace-mod-0x01-0x02.json | 76 ++++++++++++ 12 files changed, 307 insertions(+), 53 deletions(-) create mode 100644 src/test/java/net/consensys/linea/zktracer/AbstractBaseModuleTracerTest.java create mode 100644 src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerBySpecTest.java rename src/test/java/net/consensys/linea/zktracer/{module/AbstractModuleTracerTest.java => AbstractModuleTracerCorsetTest.java} (59%) rename src/test/java/net/consensys/linea/{ => zktracer/corset}/CorsetValidator.java (99%) rename src/test/java/net/consensys/linea/zktracer/{ => corset}/module/alu/add/AddTracerTest.java (92%) rename src/test/java/net/consensys/linea/zktracer/{ => corset}/module/alu/add/AdderTest.java (95%) rename src/test/java/net/consensys/linea/zktracer/{ => corset}/module/alu/mod/ModTracerTest.java (95%) rename src/test/java/net/consensys/linea/zktracer/{ => corset}/module/shf/ShfTracerTest.java (96%) rename src/test/java/net/consensys/linea/zktracer/{ => corset}/module/wcp/WcpTracerTest.java (95%) create mode 100644 src/test/java/net/consensys/linea/zktracer/specs/ModTracerBySpecTest.java create mode 100644 src/test/resources/net/consensys/linea/zktracer/mod/trace-mod-0x01-0x02.json diff --git a/build.gradle b/build.gradle index ff44f3d9f0..963ebb0b72 100644 --- a/build.gradle +++ b/build.gradle @@ -104,7 +104,7 @@ allprojects { implementation "org.hyperledger.besu:plugin-api:$besuVersion" - compileOnly 'com.fasterxml.jackson.core:jackson-databind' + implementation 'com.fasterxml.jackson.core:jackson-databind' errorprone("com.google.errorprone:error_prone_core") @@ -113,7 +113,7 @@ allprojects { implementation 'org.apache.logging.log4j:log4j-api:2.20.0' implementation 'org.apache.logging.log4j:log4j-core:2.20.0' - compileOnly 'com.fasterxml.jackson.core:jackson-databind:2.14.2' + implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.2' implementation 'org.apache.tuweni:tuweni-bytes:2.3.1' implementation 'org.apache.tuweni:tuweni-units:2.3.1' diff --git a/src/test/java/net/consensys/linea/zktracer/AbstractBaseModuleTracerTest.java b/src/test/java/net/consensys/linea/zktracer/AbstractBaseModuleTracerTest.java new file mode 100644 index 0000000000..72e999668f --- /dev/null +++ b/src/test/java/net/consensys/linea/zktracer/AbstractBaseModuleTracerTest.java @@ -0,0 +1,66 @@ +/* + * 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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.operation.Operation; + +import java.util.List; + +import net.consensys.linea.zktracer.corset.CorsetValidator; +import net.consensys.linea.zktracer.module.ModuleTracer; +import org.apache.tuweni.bytes.Bytes32; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; + +@TestInstance(Lifecycle.PER_CLASS) +public abstract class AbstractBaseModuleTracerTest { + private ZkTracer zkTracer; + private ZkTraceBuilder zkTraceBuilder; + MessageFrame mockFrame; + Operation mockOperation; + static ModuleTracer moduleTracer; + + protected void runTest(OpCode opCode, final Bytes32 arg1, Bytes32 arg2) { + String trace = generateTrace(opCode, List.of(arg1, arg2)); + assertThat(CorsetValidator.isValid(trace)).isTrue(); + } + + protected String generateTrace(OpCode opCode, List arguments) { + when(mockOperation.getOpcode()).thenReturn((int) opCode.value); + for (int i = 0; i < arguments.size(); i++) { + when(mockFrame.getStackItem(i)).thenReturn(arguments.get(i)); + } + zkTracer.tracePreExecution(mockFrame); + return zkTraceBuilder.build().toJson(); + } + + @BeforeEach + void setUp() { + zkTraceBuilder = new ZkTraceBuilder(); + moduleTracer = getModuleTracer(); + zkTracer = new ZkTracer(zkTraceBuilder, List.of(moduleTracer)); + mockFrame = mock(MessageFrame.class); + mockOperation = mock(Operation.class); + when(mockFrame.getCurrentOperation()).thenReturn(mockOperation); + } + + protected abstract ModuleTracer getModuleTracer(); +} diff --git a/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerBySpecTest.java b/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerBySpecTest.java new file mode 100644 index 0000000000..5937804033 --- /dev/null +++ b/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerBySpecTest.java @@ -0,0 +1,110 @@ +/* + * 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; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.util.Preconditions.checkState; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Stream; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.tuweni.bytes.Bytes32; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.TestInstance.Lifecycle; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +@TestInstance(Lifecycle.PER_CLASS) +public abstract class AbstractModuleTracerBySpecTest extends AbstractBaseModuleTracerTest { + private static final ObjectMapper MAPPER = new ObjectMapper(); + + @ParameterizedTest(name = "{index} {0}") + @MethodSource("specs") + public void traceWithSpecFile(final String ignored, URL specUrl) throws IOException { + traceCall(specUrl); + } + + private void traceCall(final URL specFile) throws IOException { + InputStream inputStream = specFile.openStream(); + final ObjectNode specNode = (ObjectNode) MAPPER.readTree(inputStream); + final JsonNode request = specNode.get("input"); + final JsonNode expectedTrace = specNode.get("output"); + final JsonNode actualTrace = generateTrace(getModuleTracer().jsonKey(), request); + + assertThat(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(actualTrace)) + .isEqualTo(MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(expectedTrace)); + } + + private JsonNode generateTrace(String moduleName, JsonNode jsonNodeParams) + throws JsonProcessingException { + OpCode opcode = OpCode.valueOf(jsonNodeParams.get("opcode").asText()); + List arguments = new ArrayList<>(); + JsonNode arg = jsonNodeParams.get("params"); + arg.forEach(bytes -> arguments.add(Bytes32.fromHexString(bytes.asText()))); + String trace = generateTrace(opcode, arguments); + return MAPPER.readTree(trace).get(moduleName); + } + + public static Object[][] findSpecFiles(final String[] subDirectoryPaths) { + final List specFiles = new ArrayList<>(); + for (final String path : subDirectoryPaths) { + final URL url = AbstractModuleTracerBySpecTest.class.getResource(path); + checkState(url != null, "Cannot find test directory " + path); + final Path dir; + try { + dir = Paths.get(url.toURI()); + } catch (final URISyntaxException e) { + throw new RuntimeException("Problem converting URL to URI " + url, e); + } + try (final Stream s = Files.walk(dir, 1)) { + s.map(Path::toFile) + .filter(f -> f.getPath().endsWith(".json")) + .map(AbstractModuleTracerBySpecTest::fileToParams) + .forEach(specFiles::add); + } catch (final IOException e) { + throw new RuntimeException("Problem reading directory " + dir, e); + } + } + final Object[][] result = new Object[specFiles.size()][2]; + for (int i = 0; i < specFiles.size(); i++) { + result[i] = specFiles.get(i); + } + return result; + } + + private static Object[] fileToParams(final File file) { + try { + final String fileName = file.toPath().getFileName().toString(); + final URL fileURL = file.toURI().toURL(); + return new Object[] {fileName, fileURL}; + } catch (final MalformedURLException e) { + throw new RuntimeException("Problem reading spec file " + file.getAbsolutePath(), e); + } + } +} diff --git a/src/test/java/net/consensys/linea/zktracer/module/AbstractModuleTracerTest.java b/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java similarity index 59% rename from src/test/java/net/consensys/linea/zktracer/module/AbstractModuleTracerTest.java rename to src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java index c15beb3e76..603f099350 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/AbstractModuleTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/AbstractModuleTracerCorsetTest.java @@ -12,43 +12,25 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.operation.Operation; +package net.consensys.linea.zktracer; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.stream.Stream; -import net.consensys.linea.CorsetValidator; -import net.consensys.linea.zktracer.OpCode; -import net.consensys.linea.zktracer.ZkTraceBuilder; -import net.consensys.linea.zktracer.ZkTracer; import org.apache.tuweni.bytes.Bytes32; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.TestInstance.Lifecycle; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import org.mockito.Mock; @TestInstance(Lifecycle.PER_CLASS) -public abstract class AbstractModuleTracerTest { +public abstract class AbstractModuleTracerCorsetTest extends AbstractBaseModuleTracerTest { static final Random rand = new Random(); private static final int TEST_REPETITIONS = 8; - private ZkTracer zkTracer; - private ZkTraceBuilder zkTraceBuilder; - @Mock MessageFrame mockFrame; - @Mock Operation mockOperation; - static ModuleTracer moduleTracer; - @ParameterizedTest() @MethodSource("provideRandomArguments") void randomArgumentsTest(OpCode opCode, final Bytes32 arg1, Bytes32 arg2) { @@ -61,22 +43,6 @@ void nonRandomArgumentsTest(OpCode opCode, final Bytes32 arg1, Bytes32 arg2) { runTest(opCode, arg1, arg2); } - protected void runTest(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(); - } - - @BeforeEach - void setUp() { - zkTraceBuilder = new ZkTraceBuilder(); - moduleTracer = getModuleTracer(); - zkTracer = new ZkTracer(zkTraceBuilder, List.of(moduleTracer)); - when(mockFrame.getCurrentOperation()).thenReturn(mockOperation); - } - protected abstract Stream provideNonRandomArguments(); public Stream provideRandomArguments() { @@ -89,9 +55,7 @@ public Stream provideRandomArguments() { return arguments.stream(); } - protected abstract ModuleTracer getModuleTracer(); - - protected OpCode getRandomSupportedOpcode() { + public OpCode getRandomSupportedOpcode() { var supportedOpCodes = getModuleTracer().supportedOpCodes(); int index = rand.nextInt(supportedOpCodes.size()); return supportedOpCodes.get(index); diff --git a/src/test/java/net/consensys/linea/CorsetValidator.java b/src/test/java/net/consensys/linea/zktracer/corset/CorsetValidator.java similarity index 99% rename from src/test/java/net/consensys/linea/CorsetValidator.java rename to src/test/java/net/consensys/linea/zktracer/corset/CorsetValidator.java index fe5145e1b3..5dc1166df9 100644 --- a/src/test/java/net/consensys/linea/CorsetValidator.java +++ b/src/test/java/net/consensys/linea/zktracer/corset/CorsetValidator.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea; +package net.consensys.linea.zktracer.corset; import static java.nio.file.StandardOpenOption.WRITE; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java b/src/test/java/net/consensys/linea/zktracer/corset/module/alu/add/AddTracerTest.java similarity index 92% rename from src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java rename to src/test/java/net/consensys/linea/zktracer/corset/module/alu/add/AddTracerTest.java index 402269d635..679cd49a9e 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AddTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/corset/module/alu/add/AddTracerTest.java @@ -12,16 +12,17 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.alu.add; +package net.consensys.linea.zktracer.corset.module.alu.add; import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.stream.Stream; +import net.consensys.linea.zktracer.AbstractModuleTracerCorsetTest; import net.consensys.linea.zktracer.OpCode; -import net.consensys.linea.zktracer.module.AbstractModuleTracerTest; 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; @@ -32,7 +33,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class AddTracerTest extends AbstractModuleTracerTest { +class AddTracerTest extends AbstractModuleTracerCorsetTest { private static final Random rand = new Random(); private static final int TEST_ADD_REPETITIONS = 16; diff --git a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java b/src/test/java/net/consensys/linea/zktracer/corset/module/alu/add/AdderTest.java similarity index 95% rename from src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java rename to src/test/java/net/consensys/linea/zktracer/corset/module/alu/add/AdderTest.java index 590c74bb96..3b28987e43 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/add/AdderTest.java +++ b/src/test/java/net/consensys/linea/zktracer/corset/module/alu/add/AdderTest.java @@ -12,12 +12,13 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.alu.add; +package net.consensys.linea.zktracer.corset.module.alu.add; import static org.assertj.core.api.Assertions.assertThat; 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/mod/ModTracerTest.java b/src/test/java/net/consensys/linea/zktracer/corset/module/alu/mod/ModTracerTest.java similarity index 95% rename from src/test/java/net/consensys/linea/zktracer/module/alu/mod/ModTracerTest.java rename to src/test/java/net/consensys/linea/zktracer/corset/module/alu/mod/ModTracerTest.java index a76ffe5d5b..20bee2e912 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/alu/mod/ModTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/corset/module/alu/mod/ModTracerTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.alu.mod; +package net.consensys.linea.zktracer.corset.module.alu.mod; import java.math.BigInteger; import java.util.ArrayList; @@ -20,9 +20,10 @@ import java.util.Random; import java.util.stream.Stream; +import net.consensys.linea.zktracer.AbstractModuleTracerCorsetTest; import net.consensys.linea.zktracer.OpCode; -import net.consensys.linea.zktracer.module.AbstractModuleTracerTest; 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; @@ -33,7 +34,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @ExtendWith(MockitoExtension.class) -class ModTracerTest extends AbstractModuleTracerTest { +class ModTracerTest extends AbstractModuleTracerCorsetTest { static final Random rand = new Random(); final int TEST_MOD_REPETITIONS = 16; diff --git a/src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java b/src/test/java/net/consensys/linea/zktracer/corset/module/shf/ShfTracerTest.java similarity index 96% rename from src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java rename to src/test/java/net/consensys/linea/zktracer/corset/module/shf/ShfTracerTest.java index 4fdbef96b6..ac0bcd7bc5 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/shf/ShfTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/corset/module/shf/ShfTracerTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.shf; +package net.consensys.linea.zktracer.corset.module.shf; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.when; @@ -24,10 +24,11 @@ import java.util.Random; import java.util.stream.Stream; -import net.consensys.linea.CorsetValidator; 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.shf.ShfTracer; import org.apache.tuweni.bytes.Bytes; import org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.BeforeEach; diff --git a/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java b/src/test/java/net/consensys/linea/zktracer/corset/module/wcp/WcpTracerTest.java similarity index 95% rename from src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java rename to src/test/java/net/consensys/linea/zktracer/corset/module/wcp/WcpTracerTest.java index 775fdf28d6..038bde857e 100644 --- a/src/test/java/net/consensys/linea/zktracer/module/wcp/WcpTracerTest.java +++ b/src/test/java/net/consensys/linea/zktracer/corset/module/wcp/WcpTracerTest.java @@ -12,7 +12,7 @@ * * SPDX-License-Identifier: Apache-2.0 */ -package net.consensys.linea.zktracer.module.wcp; +package net.consensys.linea.zktracer.corset.module.wcp; import static net.consensys.linea.zktracer.OpCode.SGT; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -26,10 +26,11 @@ import java.util.Random; import java.util.stream.Stream; -import net.consensys.linea.CorsetValidator; 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 org.apache.tuweni.bytes.Bytes32; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/net/consensys/linea/zktracer/specs/ModTracerBySpecTest.java b/src/test/java/net/consensys/linea/zktracer/specs/ModTracerBySpecTest.java new file mode 100644 index 0000000000..10020ae3d6 --- /dev/null +++ b/src/test/java/net/consensys/linea/zktracer/specs/ModTracerBySpecTest.java @@ -0,0 +1,33 @@ +/* + * 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.specs; + +import net.consensys.linea.zktracer.AbstractModuleTracerBySpecTest; +import net.consensys.linea.zktracer.module.ModuleTracer; +import net.consensys.linea.zktracer.module.alu.mod.ModTracer; + +public class ModTracerBySpecTest extends AbstractModuleTracerBySpecTest { + + static ModuleTracer tracer = new ModTracer(); + + public static Object[][] specs() { + return findSpecFiles(new String[] {tracer.jsonKey()}); + } + + @Override + protected ModuleTracer getModuleTracer() { + return tracer; + } +} diff --git a/src/test/resources/net/consensys/linea/zktracer/mod/trace-mod-0x01-0x02.json b/src/test/resources/net/consensys/linea/zktracer/mod/trace-mod-0x01-0x02.json new file mode 100644 index 0000000000..391c42ed8d --- /dev/null +++ b/src/test/resources/net/consensys/linea/zktracer/mod/trace-mod-0x01-0x02.json @@ -0,0 +1,76 @@ +{ + "input":{ + "opcode":"MOD", + "params":[ + "0x01", + "0x02" + ] + }, + "output":{ + "Trace" : { + "ACC_1_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_1_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_2_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_2_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_B_0" : [ 0, 0, 0, 0, 0, 0, 0, 2 ], + "ACC_B_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_B_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_B_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_DELTA_0" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_DELTA_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_DELTA_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_DELTA_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_H_0" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_H_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_H_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_Q_0" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_Q_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_Q_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_Q_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_R_0" : [ 0, 0, 0, 0, 0, 0, 0, 1 ], + "ACC_R_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_R_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ACC_R_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ARG_1_HI" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ARG_1_LO" : [ 1, 1, 1, 1, 1, 1, 1, 1 ], + "ARG_2_HI" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "ARG_2_LO" : [ 2, 2, 2, 2, 2, 2, 2, 2 ], + "BYTE_1_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_1_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_2_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_2_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_B_0" : [ 0, 0, 0, 0, 0, 0, 0, 2 ], + "BYTE_B_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_B_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_B_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_DELTA_0" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_DELTA_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_DELTA_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_DELTA_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_H_0" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_H_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_H_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_Q_0" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_Q_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_Q_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_Q_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_R_0" : [ 0, 0, 0, 0, 0, 0, 0, 1 ], + "BYTE_R_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_R_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "BYTE_R_3" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "CMP_1" : [ 1, 0, 0, 0, 0, 0, 0, 0 ], + "CMP_2" : [ 0, 1, 1, 1, 0, 0, 0, 0 ], + "CT" : [ 0, 1, 2, 3, 4, 5, 6, 7 ], + "DEC_OUTPUT" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "DEC_SIGNED" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "INST" : [ 6, 6, 6, 6, 6, 6, 6, 6 ], + "MSB_1" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "MSB_2" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "OLI" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "RES_HI" : [ 0, 0, 0, 0, 0, 0, 0, 0 ], + "RES_LO" : [ 1, 1, 1, 1, 1, 1, 1, 1 ], + "STAMP" : [ 1, 1, 1, 1, 1, 1, 1, 1 ] + }, + "Stamp" : 1 + } +} \ No newline at end of file