diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java index 7ce39c801..ebdab0d36 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/Blockhash.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.blockhash; import static com.google.common.base.Preconditions.checkArgument; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import java.nio.MappedByteBuffer; import java.util.HashMap; @@ -89,12 +90,14 @@ public void resolvePostExecution( Hub hub, MessageFrame frame, Operation.OperationResult operationResult) { final OpCode opCode = OpCode.of(frame.getCurrentOperation().getOpcode()); - if (opCode == OpCode.BLOCKHASH) { - final Bytes32 blockhashRes = Bytes32.leftPad(frame.getStackItem(0)); - operations.add(new BlockhashOperation(relBlock, absBlock, blockhashArg, blockhashRes, wcp)); - if (blockhashRes != Bytes32.ZERO) { - blockHashMap.put(blockhashArg, blockhashRes); - } + checkArgument(opCode == OpCode.BLOCKHASH); + final Bytes32 blockhashRes = Bytes32.leftPad(frame.getStackItem(0)); + operations.add(new BlockhashOperation(relBlock, absBlock, blockhashArg, blockhashRes, wcp)); + // We have 4 LLARGE and one OLI call to WCP, made at the end of the conflation, so we need to + // add line count to WCP + wcp.additionalRows.add(4 * LLARGE + 1); + if (blockhashRes != Bytes32.ZERO) { + blockHashMap.put(blockhashArg, blockhashRes); } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/BlockhashOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/BlockhashOperation.java index f0285cb51..a665c648e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/BlockhashOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockhash/BlockhashOperation.java @@ -17,10 +17,7 @@ import static net.consensys.linea.zktracer.module.blockhash.Trace.BLOCKHASH_DEPTH; import static net.consensys.linea.zktracer.module.blockhash.Trace.nROWS_PRPRC; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_EQ; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_LT; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; -import static net.consensys.linea.zktracer.module.constants.GlobalConstants.WCP_INST_LEQ; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.*; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -60,36 +57,30 @@ public BlockhashOperation( } void handlePreprocessing(Bytes32 prevBlockhashArg) { - final Bytes prevBHArgHi = prevBlockhashArg.slice(0, LLARGE); - final Bytes prevBHArgLo = prevBlockhashArg.slice(LLARGE, LLARGE); - final Bytes currBHArgHi = blockhashArg.slice(0, LLARGE); - final Bytes curBHArgLo = blockhashArg.slice(LLARGE, LLARGE); // NOTE: w goes from 0 to 4 because it refers to the array // however, rows go from i+1 to i+5 because it refers the MACRO row (index i) // row i + 1 - wcpCallToLEQ(0, prevBHArgHi, prevBHArgLo, currBHArgHi, curBHArgLo); + wcpCallToLEQ(0, prevBlockhashArg, blockhashArg); // row i + 2 - boolean sameBHArg = wcpCallToEQ(1, prevBHArgHi, prevBHArgLo, currBHArgHi, curBHArgLo); + wcpCallToEQ(1, prevBlockhashArg, blockhashArg); // row i + 3 - boolean res3 = + final boolean blockNumberGreaterThan256 = wcpCallToLEQ( - 2, Bytes.of(0), Bytes.ofUnsignedInt(256), Bytes.of(0), Bytes.ofUnsignedLong(absBlock)); - long minimalReachable = 0; - if (res3) { - minimalReachable = absBlock - 256; - } + 2, + Bytes32.leftPad(Bytes.of(BLOCKHASH_MAX_HISTORY)), + Bytes32.leftPad(Bytes.ofUnsignedLong(absBlock))); + final long minimalReachable = blockNumberGreaterThan256 ? absBlock - BLOCKHASH_MAX_HISTORY : 0; // row i + 4 - boolean upperBoundOk = - wcpCallToLT(3, currBHArgHi, curBHArgLo, Bytes.of(0), Bytes.ofUnsignedLong(absBlock)); + final boolean upperBoundOk = + wcpCallToLT(3, blockhashArg, Bytes32.leftPad(Bytes.ofUnsignedLong(absBlock))); // row i + 5 - boolean lowerBoundOk = - wcpCallToLEQ( - 4, Bytes.of(0), Bytes.ofUnsignedLong(minimalReachable), currBHArgHi, curBHArgLo); + final boolean lowerBoundOk = + wcpCallToLEQ(4, Bytes32.leftPad(Bytes.ofUnsignedLong(minimalReachable)), blockhashArg); } @Override @@ -132,42 +123,33 @@ public void tracePreprocessing(Trace trace) { } // WCP calls - private boolean wcpCallToLT( - int w, Bytes exoArg1Hi, Bytes exoArg1Lo, Bytes exoArg2Hi, Bytes exoArg2Lo) { + private boolean wcpCallToLT(int w, Bytes32 exoArg1, Bytes32 exoArg2) { this.exoInst[w] = EVM_INST_LT; - this.exoArg1Hi[w] = exoArg1Hi; - this.exoArg1Lo[w] = exoArg1Lo; - this.exoArg2Hi[w] = exoArg2Hi; - this.exoArg2Lo[w] = exoArg2Lo; - this.exoRes[w] = - wcp.callLT( - Bytes.concatenate(exoArg1Hi, exoArg1Lo), Bytes.concatenate(exoArg2Hi, exoArg2Lo)); + this.exoArg1Hi[w] = exoArg1.slice(0, LLARGE); + this.exoArg1Lo[w] = exoArg1.slice(LLARGE, LLARGE); + this.exoArg2Hi[w] = exoArg2.slice(0, LLARGE); + this.exoArg2Lo[w] = exoArg2.slice(LLARGE, LLARGE); + this.exoRes[w] = wcp.callLT(exoArg1, exoArg2); return this.exoRes[w]; } - private boolean wcpCallToLEQ( - int w, Bytes exoArg1Hi, Bytes exoArg1Lo, Bytes exoArg2Hi, Bytes exoArg2Lo) { + private boolean wcpCallToLEQ(int w, Bytes32 exoArg1, Bytes32 exoArg2) { this.exoInst[w] = WCP_INST_LEQ; - this.exoArg1Hi[w] = exoArg1Hi; - this.exoArg1Lo[w] = exoArg1Lo; - this.exoArg2Hi[w] = exoArg2Hi; - this.exoArg2Lo[w] = exoArg2Lo; - this.exoRes[w] = - wcp.callLEQ( - Bytes.concatenate(exoArg1Hi, exoArg1Lo), Bytes.concatenate(exoArg2Hi, exoArg2Lo)); + this.exoArg1Hi[w] = exoArg1.slice(0, LLARGE); + this.exoArg1Lo[w] = exoArg1.slice(LLARGE, LLARGE); + this.exoArg2Hi[w] = exoArg2.slice(0, LLARGE); + this.exoArg2Lo[w] = exoArg2.slice(LLARGE, LLARGE); + this.exoRes[w] = wcp.callLEQ(exoArg1, exoArg2); return this.exoRes[w]; } - private boolean wcpCallToEQ( - int w, Bytes exoArg1Hi, Bytes exoArg1Lo, Bytes exoArg2Hi, Bytes exoArg2Lo) { + private boolean wcpCallToEQ(int w, Bytes32 exoArg1, Bytes32 exoArg2) { this.exoInst[w] = EVM_INST_EQ; - this.exoArg1Hi[w] = exoArg1Hi; - this.exoArg1Lo[w] = exoArg1Lo; - this.exoArg2Hi[w] = exoArg2Hi; - this.exoArg2Lo[w] = exoArg2Lo; - this.exoRes[w] = - wcp.callEQ( - Bytes.concatenate(exoArg1Hi, exoArg1Lo), Bytes.concatenate(exoArg2Hi, exoArg2Lo)); + this.exoArg1Hi[w] = exoArg1.slice(0, LLARGE); + this.exoArg1Lo[w] = exoArg1.slice(LLARGE, LLARGE); + this.exoArg2Hi[w] = exoArg2.slice(0, LLARGE); + this.exoArg2Lo[w] = exoArg2.slice(LLARGE, LLARGE); + this.exoRes[w] = wcp.callEQ(exoArg1, exoArg2); return this.exoRes[w]; } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java index 0f5b8249a..500af4264 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/euc/Euc.java @@ -48,6 +48,18 @@ public String moduleKey() { return "EUC"; } + @Override + public void enterTransaction() { + OperationSetModule.super.enterTransaction(); + additionalRows.lineCount(); + } + + @Override + public void popTransaction() { + OperationSetModule.super.popTransaction(); + additionalRows.pop(); + } + @Override public List columnsHeaders() { return Trace.headers(this.lineCount());