From ad7d70da22f68d6154c0d697e4167f0098282a64 Mon Sep 17 00:00:00 2001 From: Franklin Delehelle Date: Wed, 6 Dec 2023 12:38:26 +0100 Subject: [PATCH] fix: missing hash/equals implementation --- .../linea/zktracer/bytestheta/BaseBytes.java | 15 ++++++ .../zktracer/module/ext/ExtOperation.java | 8 +-- .../linea/zktracer/module/hub/Hub.java | 1 - .../module/ext/TestDuplicatedOperations.java | 53 +++++++++++++++++++ 4 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java index 8489b38282..7f4a59746a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/bytestheta/BaseBytes.java @@ -15,6 +15,8 @@ package net.consensys.linea.zktracer.bytestheta; +import java.util.Objects; + import net.consensys.linea.zktracer.types.Bytes16; import org.apache.tuweni.bytes.Bytes32; import org.apache.tuweni.bytes.MutableBytes32; @@ -50,6 +52,19 @@ protected BaseBytes(final Bytes32 arg) { bytes32 = arg.mutableCopy(); } + @Override + public int hashCode() { + return Objects.hash(this.bytes32); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final BaseBytes that = (BaseBytes) o; + return Objects.equals(this.bytes32, that.bytes32); + } + /** * Returns a new `Bytes16` object that is the high section (first 16 bytes) of the bytes32` * instance variable. diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java index 66ffb7689b..f0b3427a90 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ext/ExtOperation.java @@ -67,10 +67,10 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final ExtOperation that = (ExtOperation) o; - return Objects.equals(opCode, that.opCode) - && Objects.equals(arg1, that.arg1) - && Objects.equals(arg2, that.arg2) - && Objects.equals(arg3, that.arg3); + return Objects.equals(this.opCode, that.opCode) + && Objects.equals(this.arg1, that.arg1) + && Objects.equals(this.arg2, that.arg2) + && Objects.equals(this.arg3, that.arg3); } public ExtOperation(OpCode opCode, Bytes32 arg1, Bytes32 arg2, Bytes32 arg3) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java index 0746759523..40bf6f0562 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java @@ -901,7 +901,6 @@ public int lineCount() { return this.state.lineCount(); } - public int cumulatedTxCount() { return this.state.txCount(); } 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 new file mode 100644 index 0000000000..ef1fe20151 --- /dev/null +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/module/ext/TestDuplicatedOperations.java @@ -0,0 +1,53 @@ +/* + * 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.ext; + +import static org.assertj.core.api.Assertions.assertThat; + +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.testing.EvmExtension; +import org.apache.tuweni.bytes.Bytes; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(EvmExtension.class) +public class TestDuplicatedOperations { + @Test + void testDuplicate() { + BytecodeRunner.of( + BytecodeCompiler.newProgram() + .push( + Bytes.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .push(0) + .push(0) + .op(OpCode.MULMOD) + .push( + Bytes.fromHexString( + "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) + .push(0) + .push(0) + .op(OpCode.MULMOD) + .compile()) + .zkTracerValidator( + zkTracer -> { + assertThat(zkTracer.getModulesLineCount().get("EXT")).isEqualTo(9); + }) + .run(); + } +}