From 971c4f2a962007508437785b65860e4eb60e3d56 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Wed, 22 Jan 2025 17:15:34 +0100 Subject: [PATCH] fix wcp line count for operations coming from block data Signed-off-by: F Bojarski --- .../zktracer/module/blockdata/Blockdata.java | 66 ++++++++++--------- .../module/blockdata/BlockdataOperation.java | 11 ++-- .../linea/zktracer/module/euc/Euc.java | 11 ++++ linea-constraints | 2 +- 4 files changed, 50 insertions(+), 40 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java index 094b9949e5..c97fb70340 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/Blockdata.java @@ -15,7 +15,9 @@ package net.consensys.linea.zktracer.module.blockdata; +import static net.consensys.linea.zktracer.module.blockdata.Trace.GAS_LIMIT_MAXIMUM; import static net.consensys.linea.zktracer.module.blockdata.Trace.nROWS_DEPTH; +import static net.consensys.linea.zktracer.module.constants.GlobalConstants.LLARGE; import java.math.BigInteger; import java.nio.MappedByteBuffer; @@ -30,7 +32,6 @@ import net.consensys.linea.zktracer.opcode.OpCode; import net.consensys.linea.zktracer.types.EWord; import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.evm.worldstate.WorldView; import org.hyperledger.besu.plugin.data.BlockBody; import org.hyperledger.besu.plugin.data.BlockHeader; @@ -41,12 +42,8 @@ public class Blockdata implements Module { private final TxnData txnData; private final Deque operations = new ArrayDeque<>(); - private static final int TIMESTAMP_BYTESIZE = 4; - private BlockHeader prevBlockHeader; - private int traceCounter = 0; private long firstBlockNumber; private Bytes chainId; - private boolean shouldBeTraced = true; final OpCode[] opCodes = { OpCode.COINBASE, @@ -69,42 +66,47 @@ public String moduleKey() { @Override public void traceStartConflation(final long blockCount) { - wcp.additionalRows.add(TIMESTAMP_BYTESIZE); // TODO: check + wcp.additionalRows.add( + LLARGE // for COINBASE + + 6 + + 6 // for TIMESTAMP + + 1 + + 6 // for NUMBER + + 1 // for DIFFICULTY + + Bytes.minimalBytes(GAS_LIMIT_MAXIMUM).size() * 4 // for GASLIMIT + + LLARGE // for CHAINID + + LLARGE // for BASEFEE + ); + + euc.additionalRows.add(8); } @Override public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBody) { final long blockNumber = blockHeader.getNumber(); - firstBlockNumber = (traceCounter < opCodes.length) ? blockNumber : firstBlockNumber; - if (shouldBeTraced) { - for (OpCode opCode : opCodes) { - BlockdataOperation operation = - new BlockdataOperation( - txnData.hub(), - blockHeader, - prevBlockHeader, - txnData.currentBlock().getNbOfTxsInBlock(), - wcp, - euc, - chainId, - opCode, - firstBlockNumber); - operations.addLast(operation); - // Increase counter to track where we are in the conflation - traceCounter++; - } + if (operations.isEmpty()) { + firstBlockNumber = blockNumber; + } + final BlockHeader previousBlockHeader = + operations.isEmpty() ? null : operations.getLast().blockHeader(); + for (OpCode opCode : opCodes) { + final BlockdataOperation operation = + new BlockdataOperation( + txnData.hub(), + blockHeader, + previousBlockHeader, + txnData.currentBlock().getNbOfTxsInBlock(), + wcp, + euc, + chainId, + opCode, + firstBlockNumber); + operations.addLast(operation); } - prevBlockHeader = blockHeader; - shouldBeTraced = false; } @Override - public void traceEndConflation(final WorldView state) {} - - @Override - public void enterTransaction() { - shouldBeTraced = true; - } + public void enterTransaction() {} @Override public void popTransaction() {} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/BlockdataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/BlockdataOperation.java index 650614a19e..d15c7aa4ab 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/BlockdataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blockdata/BlockdataOperation.java @@ -142,7 +142,7 @@ private void handleCoinbase() { private void handleTimestamp() { data = EWord.of(blockHeader.getTimestamp()); - EWord prevData = + final EWord prevData = prevBlockHeader == null ? EWord.ZERO : EWord.of(prevBlockHeader.getTimestamp()); // row i @@ -182,11 +182,11 @@ private void handleGasLimit() { wcpCallToLEQ(1, data, EWord.of(Bytes.ofUnsignedLong(GAS_LIMIT_MAXIMUM))); if (!firstBlockInConflation) { - EWord prevGasLimit = EWord.of(prevBlockHeader.getGasLimit()); + final EWord prevGasLimit = EWord.of(prevBlockHeader.getGasLimit()); // row i + 2 - Bytes maxDeviation = eucCall(2, prevGasLimit, EWord.of(GAS_LIMIT_ADJUSTMENT_FACTOR)); + final Bytes maxDeviation = eucCall(2, prevGasLimit, EWord.of(GAS_LIMIT_ADJUSTMENT_FACTOR)); // row i + 3 - BigInteger safeGasLimitUpperBound = + final BigInteger safeGasLimitUpperBound = prevGasLimit.getAsBigInteger().add(maxDeviation.toUnsignedBigInteger()); wcpCallToLT(3, data, EWord.of(safeGasLimitUpperBound)); @@ -303,9 +303,6 @@ private boolean wcpCallToISZERO(int w, EWord arg1) { } private Bytes eucCall(int w, EWord arg1, EWord arg2) { - checkArgument(arg1.bitLength() / 8 <= 16); - checkArgument(arg2.bitLength() / 8 <= 16); - this.arg1[w] = arg1; this.arg2[w] = arg2; 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 3ad5932b21..0f5b8249a2 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 @@ -26,6 +26,7 @@ import lombok.experimental.Accessors; import net.consensys.linea.zktracer.ColumnHeader; import net.consensys.linea.zktracer.container.module.OperationSetModule; +import net.consensys.linea.zktracer.container.stacked.CountOnlyOperation; import net.consensys.linea.zktracer.container.stacked.ModuleOperationStackedSet; import net.consensys.linea.zktracer.module.wcp.Wcp; import org.apache.tuweni.bytes.Bytes; @@ -39,6 +40,9 @@ public class Euc implements OperationSetModule { private final ModuleOperationStackedSet operations = new ModuleOperationStackedSet<>(); + /** count the number of rows that could be added after the sequencer counts the number of line */ + public final CountOnlyOperation additionalRows = new CountOnlyOperation(); + @Override public String moduleKey() { return "EUC"; @@ -57,6 +61,13 @@ public void commit(List buffers) { } } + @Override + public int lineCount() { + return operations.conflationFinished() + ? operations.lineCount() + : operations().lineCount() + additionalRows.lineCount(); + } + public EucOperation callEUC(final Bytes dividend, final Bytes divisor) { final BigInteger dividendBI = dividend.toUnsignedBigInteger(); final BigInteger divisorBI = divisor.toUnsignedBigInteger(); diff --git a/linea-constraints b/linea-constraints index 24c71a5517..094fb722f7 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit 24c71a551721e588aefe774850aec50f7702ecc5 +Subproject commit 094fb722f7821a30d14ec6e6b84c2920c5a9ebf6