Skip to content

Commit

Permalink
fix: missing hash/equals implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Dec 6, 2023
1 parent 4b44b3c commit ad7d70d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,6 @@ public int lineCount() {
return this.state.lineCount();
}


public int cumulatedTxCount() {
return this.state.txCount();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit ad7d70d

Please sign in to comment.