From d95c86d53b6ff1bb7da8d9bbc21c1f6e8dcf7ebf Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Fri, 10 Oct 2025 09:47:28 +0530 Subject: [PATCH 1/8] feat: forced transaction Signed-off-by: F Bojarski --- .../module/IncrementAndDetectModule.java | 6 - linea-constraints | 2 +- .../linea/BlockchainReferenceTestTools.java | 27 +-- .../testing/ToyExecutionEnvironmentV2.java | 165 +++++++++--------- 4 files changed, 88 insertions(+), 112 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/IncrementAndDetectModule.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/IncrementAndDetectModule.java index 31612e5252..d00202dfe9 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/IncrementAndDetectModule.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/IncrementAndDetectModule.java @@ -15,16 +15,11 @@ package net.consensys.linea.zktracer.container.module; -import static com.google.common.base.Preconditions.checkState; - import lombok.Setter; import net.consensys.linea.zktracer.module.ModuleName; public class IncrementAndDetectModule extends IncrementingModule { - public static final String ERROR_MESSAGE_TRIED_TO_COMMIT_UNPROVABLE_TX = - "Shouldn't commit transaction as an unprovable event has been detected."; - @Setter boolean eventDetected = false; public IncrementAndDetectModule(ModuleName moduleKey) { @@ -33,7 +28,6 @@ public IncrementAndDetectModule(ModuleName moduleKey) { @Override public void commitTransactionBundle() { - checkState(!eventDetected, ERROR_MESSAGE_TRIED_TO_COMMIT_UNPROVABLE_TX); super.commitTransactionBundle(); } diff --git a/linea-constraints b/linea-constraints index 77b5e2dee2..6cebccff82 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit 77b5e2dee295ac6a597d0d568f88308c4942d437 +Subproject commit 6cebccff8230a8821be99781dbc947094afc89a8 diff --git a/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java b/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java index 54763c82c2..c36f92c671 100644 --- a/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java +++ b/reference-tests/src/test/java/net/consensys/linea/BlockchainReferenceTestTools.java @@ -15,13 +15,11 @@ package net.consensys.linea; -import static com.google.common.base.Preconditions.checkArgument; import static net.consensys.linea.BlockchainReferenceTestJson.readBlockchainReferenceTestsOutput; import static net.consensys.linea.ReferenceTestOutcomeRecorderTool.JSON_INPUT_FILENAME; import static net.consensys.linea.reporting.TracerTestBase.getForkOrDefault; import static net.consensys.linea.testing.ToyExecutionTools.addSystemAccountsIfRequired; import static net.consensys.linea.zktracer.Fork.*; -import static net.consensys.linea.zktracer.container.module.IncrementAndDetectModule.ERROR_MESSAGE_TRIED_TO_COMMIT_UNPROVABLE_TX; import static org.assertj.core.api.Assertions.assertThat; import java.nio.file.Paths; @@ -644,22 +642,15 @@ public static void executeTest(final BlockchainReferenceTestCaseSpec spec) { } } - // TODO: run it normally once we don't exclude BLS precompiles - try { - zkTracer.traceEndConflation(worldState); - ExecutionEnvironment.checkTracer( - zkTracer, - corsetValidator, - Optional.of(log), - // NOTE: just use 0 for start and end block here, since this information is not used. - 0, - 0, - null); - } catch (Exception e) { - // Tmp: we ignore this error, as BLS precompiles are excluded in prod, but not in test - checkArgument( - e.getMessage().contains(ERROR_MESSAGE_TRIED_TO_COMMIT_UNPROVABLE_TX), e.getMessage()); - } + zkTracer.traceEndConflation(worldState); + ExecutionEnvironment.checkTracer( + zkTracer, + corsetValidator, + Optional.of(log), + // NOTE: just use 0 for start and end block here, since this information is not used. + 0, + 0, + null); assertThat(blockchain.getChainHeadHash()).isEqualTo(spec.getLastBlockHash()); } diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java index c18cbb23ca..2b91f5f0e6 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java @@ -21,7 +21,6 @@ import static net.consensys.linea.zktracer.Fork.LONDON; import static net.consensys.linea.zktracer.Fork.isPostCancun; import static net.consensys.linea.zktracer.Trace.LINEA_BASE_FEE; -import static net.consensys.linea.zktracer.container.module.IncrementAndDetectModule.ERROR_MESSAGE_TRIED_TO_COMMIT_UNPROVABLE_TX; import static net.consensys.linea.zktracer.module.ModuleName.*; import java.util.*; @@ -114,94 +113,86 @@ public void run() { final GeneralStateTestCaseEipSpec generalStateTestCaseEipSpec = this.buildGeneralStateTestCaseSpec(protocolSpec); - // TODO: remove the try catch once we don't exclude BLS precompiles - try { - ToyExecutionTools.executeTest( - generalStateTestCaseEipSpec, - protocolSpec, - tracer, - transactionProcessingResultValidator, - zkTracerValidator, - testInfo); - - if (isPostCancun(tracer.getHub().fork)) { - // This is to check that the light counter is really counting more than the full tracer - final ZkTracer tracer = this.tracer; - - final Map tracerCount = tracer.getModulesLineCount(); - - final ToyExecutionEnvironmentV2 copyEnvironment = - ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) - .transactionProcessingResultValidator( - TransactionProcessingResultValidator.EMPTY_VALIDATOR) - .accounts(accounts) - .zkTracerValidator(zkTracerValidator) - .transactions(transactions) - .build(); - copyEnvironment.runForCounting(); - final Map lightCounterCount = - copyEnvironment.zkCounter.getModulesLineCount(); - - final List moduleToCheck = - copyEnvironment.zkCounter.checkedModules().stream() - .map(module -> module.moduleKey().toString()) - .toList(); - - // check that event detection is the same between tracer and counter - checkArgument( - Objects.equals( - lightCounterCount.get(POINT_EVAL.toString()), - tracerCount.get(POINT_EVAL.toString())), - "PointEval event detection is different between tracer and counter"); - checkArgument( - Objects.equals( - lightCounterCount.get(BLS.toString()), tracerCount.get(BLS.toString())), - "BLS event detection is different between tracer and counter"); - checkArgument( - lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) - >= tracerCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()), - "RIP event detection is different between tracer and counter"); + ToyExecutionTools.executeTest( + generalStateTestCaseEipSpec, + protocolSpec, + tracer, + transactionProcessingResultValidator, + zkTracerValidator, + testInfo); + + if (isPostCancun(tracer.getHub().fork)) { + // This is to check that the light counter is really counting more than the full tracer + final ZkTracer tracer = this.tracer; + + final Map tracerCount = tracer.getModulesLineCount(); + + final ToyExecutionEnvironmentV2 copyEnvironment = + ToyExecutionEnvironmentV2.builder(chainConfig, testInfo) + .transactionProcessingResultValidator( + TransactionProcessingResultValidator.EMPTY_VALIDATOR) + .accounts(accounts) + .zkTracerValidator(zkTracerValidator) + .transactions(transactions) + .build(); + copyEnvironment.runForCounting(); + final Map lightCounterCount = + copyEnvironment.zkCounter.getModulesLineCount(); + + final List moduleToCheck = + copyEnvironment.zkCounter.checkedModules().stream() + .map(module -> module.moduleKey().toString()) + .toList(); + + // check that event detection is the same between tracer and counter + checkArgument( + Objects.equals( + lightCounterCount.get(POINT_EVAL.toString()), + tracerCount.get(POINT_EVAL.toString())), + "PointEval event detection is different between tracer and counter"); + checkArgument( + Objects.equals(lightCounterCount.get(BLS.toString()), tracerCount.get(BLS.toString())), + "BLS event detection is different between tracer and counter"); + checkArgument( + lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) + >= tracerCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()), + "RIP event detection is different between tracer and counter"); + checkArgument( + lightCounterCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()) + >= tracerCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()), + "BLAKE event detection is different between tracer and counter"); + + // There is no point to check for conflation where an excluded PRC has been triggered: + if (lightCounterCount.get(POINT_EVAL.toString()) != 0 + || lightCounterCount.get(BLS.toString()) != 0 + || lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) != 0 + || lightCounterCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()) != 0) { + return; + } + + for (String module : moduleToCheck) { checkArgument( - lightCounterCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()) - >= tracerCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()), - "BLAKE event detection is different between tracer and counter"); - - // There is no point to check for conflation where an excluded PRC has been triggered: - if (lightCounterCount.get(POINT_EVAL.toString()) != 0 - || lightCounterCount.get(BLS.toString()) != 0 - || lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) != 0 - || lightCounterCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()) != 0) { - return; - } - - for (String module : moduleToCheck) { - checkArgument( - tracerCount.get(module) <= lightCounterCount.get(module), - "Module " - + module - + " has more lines in full tracer: " - + tracerCount.get(module) - + " than in light counter: " - + lightCounterCount.get(module)); - - // TODO: how to make it smart ? - - // Note: we compare to twice the (tracer count +1) to not get exceptions when tracer - // module is empty (GAS for SKIP tx for example) - // checkArgument( - // lightCounterCount.get(module) <= 2 * (tracerCount.get(module) + 1), - // "Module " - // + module - // + " has more than twice line counts in light tracer: " - // + lightCounterCount.get(module) - // + " than in full counter: " - // + tracerCount.get(module)); - } + tracerCount.get(module) <= lightCounterCount.get(module), + "Module " + + module + + " has more lines in full tracer: " + + tracerCount.get(module) + + " than in light counter: " + + lightCounterCount.get(module)); + + // TODO: how to make it smart ? + + // Note: we compare to twice the (tracer count +1) to not get exceptions when tracer + // module is empty (GAS for SKIP tx for example) + // checkArgument( + // lightCounterCount.get(module) <= 2 * (tracerCount.get(module) + 1), + // "Module " + // + module + // + " has more than twice line counts in light tracer: " + // + lightCounterCount.get(module) + // + " than in full counter: " + // + tracerCount.get(module)); } - } catch (Exception e) { - // Tmp: we ignore this error, as BLS precompiles are excluded in prod, but not in test - checkArgument( - e.getMessage().contains(ERROR_MESSAGE_TRIED_TO_COMMIT_UNPROVABLE_TX), e.getMessage()); } } } From 4fdfc93bf63e4ebc05dfa0768ca574d0de0c0f34 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Fri, 10 Oct 2025 11:56:37 +0530 Subject: [PATCH 2/8] skip bls in ZkCounter Signed-off-by: F Bojarski --- .../main/java/net/consensys/linea/zktracer/ZkCounter.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java index 5249a184ad..357472c1dc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java @@ -770,9 +770,10 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o } else { bls.detectEvent(); } - if (callDataSize != 0) { - blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); - } + // TODO: reenable me + // if (callDataSize != 0) { + // blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); + // } hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); oob.updateTally(oobLineCountForPrc(precompile)); // TODO: check if we have some MOD coming from OOB call From 8463dd5a5f929b8e3109465e18a60c1dd88c22e8 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Thu, 16 Oct 2025 08:59:13 +0530 Subject: [PATCH 3/8] remove bls and kzg detector modules Signed-off-by: F Bojarski --- .../consensys/linea/zktracer/ZkCounter.java | 17 +--- .../linea/zktracer/module/ModuleName.java | 2 - .../linea/zktracer/module/hub/Hub.java | 8 +- .../module/hub/section/call/CallSection.java | 8 -- .../net/consensys/linea/ZkCounterTest.java | 4 - ...ncunAndPraguePrecompilesExcludedTests.java | 78 ------------------- .../testing/ToyExecutionEnvironmentV2.java | 16 ---- 7 files changed, 3 insertions(+), 130 deletions(-) delete mode 100644 arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/CancunAndPraguePrecompilesExcludedTests.java diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java index e808b1b171..86f2222046 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java @@ -76,8 +76,8 @@ import static net.consensys.linea.zktracer.module.txndata.cancun.transactions.SysfNoopTransaction.NB_ROWS_TXN_DATA_SYSF_NOOP; import static net.consensys.linea.zktracer.module.txndata.cancun.transactions.SysiEip2935Transaction.NB_ROWS_TXN_DATA_SYSI_EIP2935; import static net.consensys.linea.zktracer.module.txndata.cancun.transactions.SysiEip4788Transaction.NB_ROWS_TXN_DATA_SYSI_EIP4788; -import static net.consensys.linea.zktracer.module.txndata.cancun.transactions.UserTransaction.NB_ROWS_TXN_DATA_USER_1559_SEMANTIC; -import static net.consensys.linea.zktracer.module.txndata.cancun.transactions.UserTransaction.NB_ROWS_TXN_DATA_USER_NO_1559_SEMANTIC; +import static net.consensys.linea.zktracer.module.txndata.osaka.OsakaUserTransaction.NB_ROWS_TXN_DATA_OSAKA_USER_1559_SEMANTIC; +import static net.consensys.linea.zktracer.module.txndata.osaka.OsakaUserTransaction.NB_ROWS_TXN_DATA_OSAKA_USER_NO_1559_SEMANTIC; import static net.consensys.linea.zktracer.opcode.OpCode.*; import static net.consensys.linea.zktracer.runtime.stack.Stack.MAX_STACK_SIZE; import static net.consensys.linea.zktracer.types.TransactionProcessingMetadata.computeRequiresEvmExecution; @@ -88,7 +88,6 @@ import java.util.*; import java.util.stream.Stream; -import lombok.Getter; import lombok.extern.slf4j.Slf4j; import net.consensys.linea.plugins.config.LineaL1L2BridgeSharedConfiguration; import net.consensys.linea.zktracer.container.module.CountingOnlyModule; @@ -213,11 +212,6 @@ public class ZkCounter implements LineCountingTracer { new IncrementAndDetectModule(PRECOMPILE_RIPEMD_BLOCKS); // Related to Bls - // remove me when Linea supports Cancun & Prague precompiles - @Getter - private final IncrementAndDetectModule pointEval = new IncrementAndDetectModule(POINT_EVAL) {}; - @Getter private final IncrementAndDetectModule bls = new IncrementAndDetectModule(BLS) {}; - final IncrementingModule pointEvaluationEffectiveCall = new IncrementingModule(PRECOMPILE_BLS_POINT_EVALUATION_EFFECTIVE_CALLS); final IncrementingModule pointEvaluationFailureCall = @@ -312,8 +306,6 @@ public List checkedModules() { modexpEffectiveCall, modexpLargeCall, blakeEffectiveCall, - bls, - pointEval, pointEvaluationEffectiveCall, pointEvaluationFailureCall, blsG1AddEffectiveCall, @@ -767,11 +759,6 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o PRC_BLS_MAP_FP_TO_G1, PRC_BLS_MAP_FP2_TO_G2, PRC_POINT_EVALUATION -> { - if (precompile == PRC_POINT_EVALUATION) { - pointEval.detectEvent(); - } else { - bls.detectEvent(); - } // TODO: reenable me // if (callDataSize != 0) { // blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleName.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleName.java index 7bd380d90e..adbb4ddb3e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleName.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/ModuleName.java @@ -70,8 +70,6 @@ public enum ModuleName { PRECOMPILE_RIPEMD_BLOCKS, // bls: - POINT_EVAL, - BLS, PRECOMPILE_POINT_EVALUATION_FAILURE_EFFECTIVE_CALLS, PRECOMPILE_BLS_POINT_EVALUATION_EFFECTIVE_CALLS, PRECOMPILE_BLS_G1_ADD_EFFECTIVE_CALLS, 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 628ed1cd31..bf0570b80f 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 @@ -272,10 +272,6 @@ public int spillage(Trace trace) { private final BlakeRounds blakeRounds = new BlakeRounds(); // Related to Bls - // TODO: remove me when Linea supports Cancun & Prague precompiles - private final IncrementAndDetectModule pointEval = new IncrementAndDetectModule(POINT_EVAL) {}; - private final IncrementAndDetectModule bls = new IncrementAndDetectModule(BLS) {}; - final IncrementingModule pointEvaluationEffectiveCall = new IncrementingModule(PRECOMPILE_BLS_POINT_EVALUATION_EFFECTIVE_CALLS); final IncrementingModule pointEvaluationFailureCall = @@ -337,9 +333,7 @@ public List getTracelessModules() { blsG1MembershipCalls, blsG2MembershipCalls, l1BlockSize, - l2L1Logs, - pointEval, - bls); + l2L1Logs); } /* diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java index ec9bd96e83..b43bc730ce 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/CallSection.java @@ -378,14 +378,6 @@ private void smcProcessing(Hub hub, MessageFrame frame) { } private void prcProcessing(Hub hub) { - // TODO: remove me when Linea supports Cancun & Prague precompiles - if (isKzgPrecompileCall(calleeAddress, hub.fork)) { - hub.pointEval().detectEvent(); - } - if (isBlsPrecompileCall(calleeAddress, hub.fork)) { - hub.bls().detectEvent(); - } - precompileSubsection = ADDRESS_TO_PRECOMPILE.get(calleeFirst.address()).apply(hub, this); hub.defers().scheduleForContextEntry(this); hub.defers().scheduleForContextReEntry(this, hub.currentFrame()); diff --git a/arithmetization/src/test/java/net/consensys/linea/ZkCounterTest.java b/arithmetization/src/test/java/net/consensys/linea/ZkCounterTest.java index 7b0365b46b..1a49e7fbf8 100644 --- a/arithmetization/src/test/java/net/consensys/linea/ZkCounterTest.java +++ b/arithmetization/src/test/java/net/consensys/linea/ZkCounterTest.java @@ -138,8 +138,6 @@ void twoSuccessfullL2l1Logs(TestInfo testInfo) { assertEquals(0, lineCountMap.get(ModuleName.PRECOMPILE_MODEXP_EFFECTIVE_CALLS.toString())); assertEquals(0, lineCountMap.get(PRECOMPILE_RIPEMD_BLOCKS.toString())); assertEquals(0, lineCountMap.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString())); - assertEquals(0, lineCountMap.get(POINT_EVAL.toString())); - assertEquals(0, lineCountMap.get(BLS.toString())); // L1 block size > 0 assertTrue(lineCountMap.get(BLOCK_L1_SIZE.toString()) > 0); @@ -236,8 +234,6 @@ void unsuccessfullL2l1Logs(TestInfo testInfo) { assertEquals(0, lineCountMap.get(ModuleName.PRECOMPILE_MODEXP_EFFECTIVE_CALLS.toString())); assertEquals(0, lineCountMap.get(PRECOMPILE_RIPEMD_BLOCKS.toString())); assertEquals(0, lineCountMap.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString())); - assertEquals(0, lineCountMap.get(POINT_EVAL.toString())); - assertEquals(0, lineCountMap.get(BLS.toString())); // L1 block size > 0 assertTrue(lineCountMap.get(BLOCK_L1_SIZE.toString()) > 0); diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/CancunAndPraguePrecompilesExcludedTests.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/CancunAndPraguePrecompilesExcludedTests.java deleted file mode 100644 index 0657fd9cf1..0000000000 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/CancunAndPraguePrecompilesExcludedTests.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright ConsenSys Inc. - * - * 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.precompiles; - -import static net.consensys.linea.zktracer.types.AddressUtils.*; -import static org.hyperledger.besu.datatypes.Address.KZG_POINT_EVAL; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Stream; - -import net.consensys.linea.reporting.TracerTestBase; -import net.consensys.linea.testing.BytecodeCompiler; -import net.consensys.linea.testing.BytecodeRunner; -import net.consensys.linea.zktracer.opcode.OpCode; -import org.apache.tuweni.bytes.Bytes; -import org.hyperledger.besu.datatypes.Address; -import org.junit.jupiter.api.TestInfo; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; - -public class CancunAndPraguePrecompilesExcludedTests extends TracerTestBase { - // TODO: remove me when Linea supports Cancun & Prague precompiles - @ParameterizedTest - @MethodSource("cancunAndPraguePrecompilesExclusionTestSource") - void cancunAndPraguePrecompilesExclusionTest(Address prc, TestInfo testInfo) { - final Bytes bytecode = - BytecodeCompiler.newProgram(chainConfig) - .push(0) - .push(0) - .push(0) - .push(0) - .push(0) - .push(prc) // address - .push(0xffff) // gas - .op(OpCode.CALL) - .op(OpCode.POP) - .compile(); - BytecodeRunner bytecodeRunner = BytecodeRunner.of(bytecode); - try { - bytecodeRunner.run(chainConfig, testInfo); - } catch (Exception e) { - // we don't care about execution result, just the counting. Tracing is expected to fail. - } - - // Check that the line count is made - assertEquals( - isKzgPrecompileCall(prc, chainConfig.fork) ? Integer.MAX_VALUE : 0, - bytecodeRunner.getHub().pointEval().lineCount()); - assertEquals( - isBlsPrecompileCall(prc, chainConfig.fork) ? Integer.MAX_VALUE : 0, - bytecodeRunner.getHub().bls().lineCount()); - } - - private static Stream cancunAndPraguePrecompilesExclusionTestSource() { - final List arguments = new ArrayList<>(); - for (Address address : BLS_PRECOMPILES) { - arguments.add(Arguments.of(address)); - } - arguments.add(Arguments.of(KZG_POINT_EVAL)); - return arguments.stream(); - } -} diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java index cfdf5173dc..eaf38fdac2 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java @@ -145,14 +145,6 @@ public void run() { .toList(); // check that event detection is the same between tracer and counter - checkArgument( - Objects.equals( - lightCounterCount.get(POINT_EVAL.toString()), - tracerCount.get(POINT_EVAL.toString())), - "PointEval event detection is different between tracer and counter"); - checkArgument( - Objects.equals(lightCounterCount.get(BLS.toString()), tracerCount.get(BLS.toString())), - "BLS event detection is different between tracer and counter"); checkArgument( lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) >= tracerCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()), @@ -162,14 +154,6 @@ public void run() { >= tracerCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()), "BLAKE event detection is different between tracer and counter"); - // There is no point to check for conflation where an excluded PRC has been triggered: - // if (lightCounterCount.get(POINT_EVAL.toString()) != 0 - // || lightCounterCount.get(BLS.toString()) != 0 - if (lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) != 0 - || lightCounterCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()) != 0) { - return; - } - for (String module : moduleToCheck) { checkArgument( tracerCount.get(module) <= lightCounterCount.get(module), From 69004d5d8967b84312bd6361217ce6b845cb5016 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Thu, 16 Oct 2025 09:24:51 +0530 Subject: [PATCH 4/8] counter for blake and rip also Signed-off-by: F Bojarski --- .../consensys/linea/zktracer/ZkCounter.java | 36 +++++++++++-------- .../BlakeModexpDataOperation.java | 9 +++-- .../precompileSubsection/BlakeSubsection.java | 11 +++--- .../testing/ToyExecutionEnvironmentV2.java | 10 ------ 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java index 86f2222046..5b0a520a96 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java @@ -22,6 +22,7 @@ import static net.consensys.linea.zktracer.module.ModuleName.*; import static net.consensys.linea.zktracer.module.ModuleName.GAS; import static net.consensys.linea.zktracer.module.add.AddOperation.NB_ROWS_ADD; +import static net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpDataOperation.NB_ROWS_BLAKEMODEPX_BLAKE; import static net.consensys.linea.zktracer.module.blake2fmodexpdata.BlakeModexpDataOperation.NB_ROWS_BLAKEMODEXP_MODEXP; import static net.consensys.linea.zktracer.module.blockdata.module.CancunBlockData.NB_ROWS_BLOCK_DATA; import static net.consensys.linea.zktracer.module.blockhash.BlockhashOperation.NB_ROWS_BLOCKHASH; @@ -42,6 +43,7 @@ import static net.consensys.linea.zktracer.module.hub.section.StackOnlySection.NB_ROWS_HUB_SIMPLE_STACK_OP; import static net.consensys.linea.zktracer.module.hub.section.StackRamSection.NB_ROWS_HUB_STACKRAM; import static net.consensys.linea.zktracer.module.hub.section.call.CallSection.NB_ROWS_HUB_CALL; +import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.BlakeSubsection.NB_ROWS_HUB_PRC_BLAKE; import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.EllipticCurvePrecompileSubsection.NB_ROWS_HUB_PRC_ELLIPTIC_CURVE; import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.IdentitySubsection.NB_ROWS_HUB_PRC_IDENTITY; import static net.consensys.linea.zktracer.module.hub.section.call.precompileSubsection.ModexpSubsection.NB_ROWS_HUB_PRC_MODEXP; @@ -707,15 +709,13 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o } case PRC_RIPEMD_160 -> { ripemdBlocks.detectEvent(); - // Reenable me when RIPEMD is supported by the prover - // hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); - // oob.updateTally(oobLineCountforPrc(precompile)); - // mod.updateTally(NB_ROWS_MOD); // coming from OOB call - // if (prcSuccess && callDataSize != 0) { - // shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + - // NB_ROWS_SHAKIRA_RESULT); - // ripemdBlocks.updateTally(callDataSize); - // } + hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); + oob.updateTally(oobLineCountForPrc(precompile)); + mod.updateTally(NB_ROWS_MOD); // coming from OOB call + if (prcSuccess && callDataSize != 0) { + shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + NB_ROWS_SHAKIRA_RESULT); + ripemdBlocks.updateTally(callDataSize); + } } case PRC_IDENTITY -> { hub.updateTally(NB_ROWS_HUB_PRC_IDENTITY); @@ -750,7 +750,12 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o oob.updateTally(oobLineCountForPrc(precompile)); mod.updateTally(NB_ROWS_MOD); // coming from OOB call } - case PRC_BLAKE2F -> blakeEffectiveCall.detectEvent(); + case PRC_BLAKE2F -> { + blakeEffectiveCall.updateTally(true); + hub.updateTally(NB_ROWS_HUB_PRC_BLAKE); + blakemodexp.updateTally(NB_ROWS_BLAKEMODEPX_BLAKE); + // TODO: still unchecked module for now. blakeRounds.updateTally(); + } case PRC_BLS_G1_ADD, PRC_BLS_G1_MSM, PRC_BLS_G2_ADD, @@ -759,13 +764,14 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o PRC_BLS_MAP_FP_TO_G1, PRC_BLS_MAP_FP2_TO_G2, PRC_POINT_EVALUATION -> { - // TODO: reenable me - // if (callDataSize != 0) { - // blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); - // } + if (callDataSize != 0) { + blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); + } hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); oob.updateTally(oobLineCountForPrc(precompile)); - // TODO: check if we have some MOD coming from OOB call + if (precompile.isAnyOf(PRC_BLS_G1_MSM, PRC_BLS_G2_MSM, PRC_BLS_PAIRING_CHECK)) { + mod.updateTally(NB_ROWS_MOD); // coming from OOB call + } } default -> throw new IllegalStateException("Unsupported precompile: " + precompile); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java index 9f26111fcf..7772507ffc 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpDataOperation.java @@ -46,13 +46,13 @@ @Accessors(fluent = true) public class BlakeModexpDataOperation extends ModuleOperation { - public static final int MODEXP_COMPONENT_BYTE_SIZE = LLARGE * (INDEX_MAX_MODEXP + 1); - public static final int NB_ROWS_BLAKEMODEXP_MODEXP = + public static final short MODEXP_COMPONENT_BYTE_SIZE = LLARGE * (INDEX_MAX_MODEXP + 1); + public static final short NB_ROWS_BLAKEMODEXP_MODEXP = (INDEX_MAX_MODEXP_BASE + 1) + (INDEX_MAX_MODEXP_EXPONENT + 1) + (INDEX_MAX_MODEXP_MODULUS + 1) + (INDEX_MAX_MODEXP_RESULT + 1); - private static final int BLAKE2f_COMPONENTS_LINE_COUNT = + public static final short NB_ROWS_BLAKEMODEPX_BLAKE = (INDEX_MAX_BLAKE_DATA + 1) + (INDEX_MAX_BLAKE_PARAMS + 1) + (INDEX_MAX_BLAKE_RESULT + 1); public static final short BLAKE2f_R_SIZE = 4; public static final short BLAKE2f_HASH_INPUT_OFFSET = BLAKE2f_R_SIZE; @@ -78,11 +78,10 @@ public BlakeModexpDataOperation(final BlakeComponents blakeComponents, final int @Override protected int computeLineCount() { - return modexpMetaData.isPresent() ? NB_ROWS_BLAKEMODEXP_MODEXP : BLAKE2f_COMPONENTS_LINE_COUNT; + return modexpMetaData.isPresent() ? NB_ROWS_BLAKEMODEXP_MODEXP : NB_ROWS_BLAKEMODEPX_BLAKE; } void trace(Trace.Blake2fmodexpdata trace, final int stamp) { - final UnsignedByte stampByte = UnsignedByte.of(stamp); if (modexpMetaData.isPresent()) { traceBase(trace, stamp); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java index f60dd3dbf0..b66ee51e33 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/call/precompileSubsection/BlakeSubsection.java @@ -31,6 +31,11 @@ import org.apache.tuweni.bytes.Bytes; public class BlakeSubsection extends PrecompileSubsection { + // 3 = SCEN + MISC + CON (squash caller return data): if size != 213 + // 4 = SCEN + MISC + MISC + CON (squash caller return data): if insufficient gas / f not a bit + // 6 = SCEN + MISC + (3 * MISC) + CON (provide caller with return data): if success + // we don't optimize as BLAKE calls are rare + public static final short NB_ROWS_HUB_PRC_BLAKE = 6; final Blake2fCallDataSizeOobCall blakeCdsOobCall; ImcFragment secondImcFragment; Blake2fParamsOobCall blake2fParamsOobCall; @@ -123,10 +128,6 @@ public void resolveAtContextReEntry(Hub hub, CallFrame callFrame) { @Override protected short maxNumberOfLines() { - // 3 = SCEN + MISC + CON (squash caller return data): if size != 213 - // 4 = SCEN + MISC + MISC + CON (squash caller return data): if insufficient gas / f not a bit - // 6 = SCEN + MISC + (3 * MISC) + CON (provide caller with return data): if success - // we don't optimize as BLAKE calls are rare - return 6; + return NB_ROWS_HUB_PRC_BLAKE; } } diff --git a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java index eaf38fdac2..d34a75c324 100644 --- a/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java +++ b/testing/src/main/java/net/consensys/linea/testing/ToyExecutionEnvironmentV2.java @@ -144,16 +144,6 @@ public void run() { .map(module -> module.moduleKey().toString()) .toList(); - // check that event detection is the same between tracer and counter - checkArgument( - lightCounterCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()) - >= tracerCount.get(PRECOMPILE_RIPEMD_BLOCKS.toString()), - "RIP event detection is different between tracer and counter"); - checkArgument( - lightCounterCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()) - >= tracerCount.get(PRECOMPILE_BLAKE_EFFECTIVE_CALLS.toString()), - "BLAKE event detection is different between tracer and counter"); - for (String module : moduleToCheck) { checkArgument( tracerCount.get(module) <= lightCounterCount.get(module), From ef6efec3d0accba4c702cdb9b167298ac491dde8 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Thu, 16 Oct 2025 10:38:57 +0530 Subject: [PATCH 5/8] some fixes Signed-off-by: F Bojarski --- .../main/java/net/consensys/linea/zktracer/ZkCounter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java index 5b0a520a96..52bb62f18a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java @@ -210,8 +210,7 @@ public class ZkCounter implements LineCountingTracer { // related to Shakira: private final Keccak keccak; private final Sha256Blocks sha256Blocks = new Sha256Blocks(); - private final IncrementAndDetectModule ripemdBlocks = - new IncrementAndDetectModule(PRECOMPILE_RIPEMD_BLOCKS); + private final CountingOnlyModule ripemdBlocks = new CountingOnlyModule(PRECOMPILE_RIPEMD_BLOCKS); // Related to Bls final IncrementingModule pointEvaluationEffectiveCall = @@ -708,7 +707,6 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o } } case PRC_RIPEMD_160 -> { - ripemdBlocks.detectEvent(); hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); oob.updateTally(oobLineCountForPrc(precompile)); mod.updateTally(NB_ROWS_MOD); // coming from OOB call @@ -753,8 +751,9 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o case PRC_BLAKE2F -> { blakeEffectiveCall.updateTally(true); hub.updateTally(NB_ROWS_HUB_PRC_BLAKE); + oob.updateTally(oobLineCountForPrc(PRC_BLAKE2F)); blakemodexp.updateTally(NB_ROWS_BLAKEMODEPX_BLAKE); - // TODO: still unchecked module for now. blakeRounds.updateTally(); + // TODO: still unchecked module for now: blakeRounds.updateTally(); } case PRC_BLS_G1_ADD, PRC_BLS_G1_MSM, From 62a1b2810430e24c045f1bbbb42138608b7120e3 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Thu, 16 Oct 2025 17:19:44 +0530 Subject: [PATCH 6/8] fix blsdata trigger in zkcounter Signed-off-by: F Bojarski --- .../consensys/linea/zktracer/ZkCounter.java | 8 +++- .../scenario/PrecompileScenarioFragment.java | 17 ++++++++ .../zktracer/precompiles/PrecompileUtils.java | 40 +------------------ 3 files changed, 24 insertions(+), 41 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java index 52bb62f18a..45e9c7aef7 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer; import static net.consensys.linea.zktracer.Fork.*; +import static net.consensys.linea.zktracer.Trace.*; import static net.consensys.linea.zktracer.Trace.Ecdata.TOTAL_SIZE_ECPAIRING_DATA_MIN; import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_CALL; import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_CREATE; @@ -763,14 +764,17 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o PRC_BLS_MAP_FP_TO_G1, PRC_BLS_MAP_FP2_TO_G2, PRC_POINT_EVALUATION -> { - if (callDataSize != 0) { + if (validCallDataSize(precompile, callDataSize)) { blsdata.callBls(0, precompile, frame.getInputData(), returnData, prcSuccess); } hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); oob.updateTally(oobLineCountForPrc(precompile)); - if (precompile.isAnyOf(PRC_BLS_G1_MSM, PRC_BLS_G2_MSM, PRC_BLS_PAIRING_CHECK)) { + if (precompile == PRC_BLS_PAIRING_CHECK) { mod.updateTally(NB_ROWS_MOD); // coming from OOB call } + if (precompile.isAnyOf(PRC_BLS_G1_MSM, PRC_BLS_G2_MSM)) { + mod.updateTally(2 * NB_ROWS_MOD); // coming from OOB call + } } default -> throw new IllegalStateException("Unsupported precompile: " + precompile); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 72b295efef..1ebeec1472 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -16,6 +16,7 @@ package net.consensys.linea.zktracer.module.hub.fragment.scenario; import static java.util.Map.entry; +import static net.consensys.linea.zktracer.Trace.*; import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_IDENTITY; import static net.consensys.linea.zktracer.TraceCancun.Oob.CT_MAX_RIPEMD; import static net.consensys.linea.zktracer.TracePrague.Blsdata.CT_MAX_POINT_EVALUATION; @@ -228,6 +229,22 @@ public static short oobLineCountForPrc(PrecompileFlag prc) { default -> throw new IllegalArgumentException("Precompile not supported:" + prc); }; } + + public static boolean validCallDataSize( + PrecompileScenarioFragment.PrecompileFlag prc, int cds) { + return switch (prc) { + case PRC_BLS_G1_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G1_ADD; + case PRC_BLS_G2_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G2_ADD; + case PRC_BLS_MAP_FP2_TO_G2 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP2_TO_G2; + case PRC_BLS_MAP_FP_TO_G1 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP_TO_G1; + case PRC_POINT_EVALUATION -> cds == PRECOMPILE_CALL_DATA_SIZE___POINT_EVALUATION; + case PRC_BLS_G1_MSM -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G1_MSM == 0; + case PRC_BLS_G2_MSM -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G2_MSM == 0; + case PRC_BLS_PAIRING_CHECK -> cds != 0 + && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_PAIRING_CHECK == 0; + default -> throw new IllegalArgumentException("not implemented for prc: " + prc); + }; + } } final PrecompileSubsection precompileSubSection; diff --git a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/PrecompileUtils.java b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/PrecompileUtils.java index 7118189ed0..f147fb5c02 100644 --- a/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/PrecompileUtils.java +++ b/arithmetization/src/test/java/net/consensys/linea/zktracer/precompiles/PrecompileUtils.java @@ -15,46 +15,8 @@ package net.consensys.linea.zktracer.precompiles; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLAKE2_PER_ROUND; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLS_G1_ADD; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLS_G2_ADD; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLS_MAP_FP2_TO_G2; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLS_MAP_FP_TO_G1; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLS_PAIRING_CHECK; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_BLS_PAIRING_CHECK_PAIR; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_ECADD; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_ECMUL; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_ECPAIRING; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_ECPAIRING_PAIR; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_ECRECOVER; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_IDENTITY; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_IDENTITY_WORD; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_MODEXP; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_POINT_EVALUATION; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_RIPEMD; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_RIPEMD_WORD; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_SHA2; -import static net.consensys.linea.zktracer.Trace.GAS_CONST_SHA2_WORD; -import static net.consensys.linea.zktracer.Trace.OOB_INST_BLS_G1_MSM; -import static net.consensys.linea.zktracer.Trace.OOB_INST_BLS_G2_MSM; +import static net.consensys.linea.zktracer.Trace.*; import static net.consensys.linea.zktracer.Trace.Oob.G_QUADDIVISOR; -import static net.consensys.linea.zktracer.Trace.PRC_BLS_G1_MSM_MULTIPLICATION_COST; -import static net.consensys.linea.zktracer.Trace.PRC_BLS_G2_MSM_MULTIPLICATION_COST; -import static net.consensys.linea.zktracer.Trace.PRC_BLS_MULTIPLICATION_MULTIPLIER; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G1_MSM; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G2_MSM; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_PAIRING_CHECK; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_CALL_DATA_UNIT_SIZE___ECPAIRING; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_G1_ADD; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_G1_MSM; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_G2_ADD; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_G2_MSM; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_MAP_FP2_TO_G2; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_MAP_FP_TO_G1; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___BLS_PAIRING_CHECK; -import static net.consensys.linea.zktracer.Trace.PRECOMPILE_RETURN_DATA_SIZE___POINT_EVALUATION; -import static net.consensys.linea.zktracer.Trace.WORD_SIZE; -import static net.consensys.linea.zktracer.Trace.WORD_SIZE_MO; import static net.consensys.linea.zktracer.instructionprocessing.callTests.Utilities.populateMemory; import static org.hyperledger.besu.datatypes.Address.*; From a90b9a4b652750131c44a244081f217f96bd0045 Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Thu, 23 Oct 2025 09:32:09 +0530 Subject: [PATCH 7/8] ras Signed-off-by: F Bojarski --- .../consensys/linea/zktracer/ZkCounter.java | 19 ++++++----------- .../scenario/PrecompileScenarioFragment.java | 21 +++++++++++++++---- linea-constraints | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java index 45e9c7aef7..623aee41aa 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/ZkCounter.java @@ -68,7 +68,6 @@ import static net.consensys.linea.zktracer.module.hub.section.txInitializationSection.TxInitializationSection.NB_ROWS_HUB_INIT; import static net.consensys.linea.zktracer.module.logdata.LogData.lineCountForLogData; import static net.consensys.linea.zktracer.module.loginfo.LogInfo.lineCountForLogInfo; -import static net.consensys.linea.zktracer.module.mod.ModOperation.NB_ROWS_MOD; import static net.consensys.linea.zktracer.module.mxp.moduleCall.CancunMSizeMxpCall.NB_ROWS_MXP_MSIZE; import static net.consensys.linea.zktracer.module.mxp.moduleCall.CancunStateUpdateMxpCall.NB_ROWS_MXP_UPDT_B; import static net.consensys.linea.zktracer.module.mxp.moduleCall.CancunStateUpdateWordPricingMxpCall.NB_ROWS_MXP_UPDT_W; @@ -687,7 +686,6 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o final boolean prcSuccess = frame.getState() == COMPLETED_SUCCESS; final Bytes returnData = output == null ? Bytes.EMPTY : output; - // MMU switch (precompile) { case PRC_ECRECOVER, PRC_ECADD, PRC_ECMUL -> { // trigger EcData to count the underlying EC operations @@ -701,7 +699,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o case PRC_SHA2_256 -> { hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); oob.updateTally(oobLineCountForPrc(precompile)); - mod.updateTally(NB_ROWS_MOD); // coming from OOB call + mod.updateTally(modLinesComingFromOobCall(precompile)); if (prcSuccess && callDataSize != 0) { shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + NB_ROWS_SHAKIRA_RESULT); sha256Blocks.updateTally(callData.size()); @@ -710,7 +708,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o case PRC_RIPEMD_160 -> { hub.updateTally(NB_ROWS_HUB_PRC_SHARIP); oob.updateTally(oobLineCountForPrc(precompile)); - mod.updateTally(NB_ROWS_MOD); // coming from OOB call + mod.updateTally(modLinesComingFromOobCall(precompile)); if (prcSuccess && callDataSize != 0) { shakiradata.updateTally(fromDataSizeToLimbNbRows(callDataSize) + NB_ROWS_SHAKIRA_RESULT); ripemdBlocks.updateTally(callDataSize); @@ -719,7 +717,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o case PRC_IDENTITY -> { hub.updateTally(NB_ROWS_HUB_PRC_IDENTITY); oob.updateTally(oobLineCountForPrc(precompile)); - mod.updateTally(NB_ROWS_MOD); // coming from OOB call + mod.updateTally(modLinesComingFromOobCall(precompile)); } case PRC_MODEXP -> { hub.updateTally(NB_ROWS_HUB_PRC_MODEXP); @@ -737,7 +735,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o exp.call(modexpLogCallToExp); } oob.updateTally(oobLineCountForPrc(precompile)); - mod.updateTally(2 * NB_ROWS_MOD); // 2 coming from OOB pricing call + mod.updateTally(modLinesComingFromOobCall(precompile)); } case PRC_ECPAIRING -> { // trigger EcData to count the underlying EC operations @@ -747,7 +745,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o } hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); oob.updateTally(oobLineCountForPrc(precompile)); - mod.updateTally(NB_ROWS_MOD); // coming from OOB call + mod.updateTally(modLinesComingFromOobCall(precompile)); } case PRC_BLAKE2F -> { blakeEffectiveCall.updateTally(true); @@ -769,12 +767,7 @@ public void tracePrecompileCall(MessageFrame frame, long gasRequirement, Bytes o } hub.updateTally(NB_ROWS_HUB_PRC_ELLIPTIC_CURVE); oob.updateTally(oobLineCountForPrc(precompile)); - if (precompile == PRC_BLS_PAIRING_CHECK) { - mod.updateTally(NB_ROWS_MOD); // coming from OOB call - } - if (precompile.isAnyOf(PRC_BLS_G1_MSM, PRC_BLS_G2_MSM)) { - mod.updateTally(2 * NB_ROWS_MOD); // coming from OOB call - } + mod.updateTally(modLinesComingFromOobCall(precompile)); } default -> throw new IllegalStateException("Unsupported precompile: " + precompile); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java index 1ebeec1472..0d2061189e 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/scenario/PrecompileScenarioFragment.java @@ -35,6 +35,7 @@ import static net.consensys.linea.zktracer.module.hub.fragment.imc.oob.precompiles.modexp.ModexpXbsOobCall.NB_ROWS_OOB_MODEXP_XBS; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileFlag.*; import static net.consensys.linea.zktracer.module.hub.fragment.scenario.PrecompileScenarioFragment.PrecompileScenario.*; +import static net.consensys.linea.zktracer.module.mod.ModOperation.NB_ROWS_MOD; import java.util.Map; @@ -233,18 +234,30 @@ public static short oobLineCountForPrc(PrecompileFlag prc) { public static boolean validCallDataSize( PrecompileScenarioFragment.PrecompileFlag prc, int cds) { return switch (prc) { - case PRC_BLS_G1_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G1_ADD; - case PRC_BLS_G2_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G2_ADD; - case PRC_BLS_MAP_FP2_TO_G2 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP2_TO_G2; - case PRC_BLS_MAP_FP_TO_G1 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP_TO_G1; case PRC_POINT_EVALUATION -> cds == PRECOMPILE_CALL_DATA_SIZE___POINT_EVALUATION; + case PRC_BLS_G1_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G1_ADD; case PRC_BLS_G1_MSM -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G1_MSM == 0; + case PRC_BLS_G2_ADD -> cds == PRECOMPILE_CALL_DATA_SIZE___G2_ADD; case PRC_BLS_G2_MSM -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_G2_MSM == 0; case PRC_BLS_PAIRING_CHECK -> cds != 0 && cds % PRECOMPILE_CALL_DATA_UNIT_SIZE___BLS_PAIRING_CHECK == 0; + case PRC_BLS_MAP_FP_TO_G1 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP_TO_G1; + case PRC_BLS_MAP_FP2_TO_G2 -> cds == PRECOMPILE_CALL_DATA_SIZE___FP2_TO_G2; default -> throw new IllegalArgumentException("not implemented for prc: " + prc); }; } + + public static short modLinesComingFromOobCall(PrecompileScenarioFragment.PrecompileFlag prc) { + return switch (prc) { + case PRC_SHA2_256, + PRC_RIPEMD_160, + PRC_IDENTITY, + PRC_BLS_PAIRING_CHECK, + PRC_ECPAIRING -> NB_ROWS_MOD; + case PRC_MODEXP, PRC_BLS_G1_MSM, PRC_BLS_G2_MSM -> (short) (NB_ROWS_MOD * 2); + default -> 0; + }; + } } final PrecompileSubsection precompileSubSection; diff --git a/linea-constraints b/linea-constraints index 4eb0fef019..9caf2a0735 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit 4eb0fef0197a6f2642aa15687f89537c4d2d4293 +Subproject commit 9caf2a0735069190856883b80e58eba820160d87 From 2c2dbccfdc54362b1d4d0605ee33087614806d5f Mon Sep 17 00:00:00 2001 From: F Bojarski Date: Thu, 23 Oct 2025 12:39:19 +0530 Subject: [PATCH 8/8] update constraonts Signed-off-by: F Bojarski --- linea-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linea-constraints b/linea-constraints index 9caf2a0735..d092df8513 160000 --- a/linea-constraints +++ b/linea-constraints @@ -1 +1 @@ -Subproject commit 9caf2a0735069190856883b80e58eba820160d87 +Subproject commit d092df8513edcd5819a55c09a6a8529782ffb73a