From 9c6d8525b614a3f86154c023834477a43111f376 Mon Sep 17 00:00:00 2001 From: Franklin Delehelle Date: Thu, 30 Nov 2023 15:55:27 +0100 Subject: [PATCH] temp: geth-compatibily hacks --- CHANGELOG.md | 8 +- .../src/test/resources/moduleLimits.toml | 13 ++- .../src/test/resources/noModuleLimits.toml | 13 ++- .../resources/txOverflowModuleLimits.toml | 13 ++- .../consensys/linea/zktracer/module/Util.java | 3 + .../linea/zktracer/module/hub/Hub.java | 84 ++++++++++++++----- .../linea/zktracer/module/hub/TxTrace.java | 4 +- .../zktracer/module/legacy/hash/HashData.java | 77 +++++++++++++++++ .../zktracer/module/legacy/hash/HashInfo.java | 72 ++++++++++++++++ .../precompiles/AbstractCallCounter.java | 57 +++++++++++++ .../precompiles/Blake2fCallCounter.java | 23 +++++ .../limits/precompiles/Blake2fRounds.java | 8 +- .../limits/precompiles/EcAddCallCounter.java | 23 +++++ .../precompiles/EcAddEffectiveCall.java | 6 ++ .../limits/precompiles/EcMulCallCounter.java | 23 +++++ .../precompiles/EcMulEffectiveCall.java | 7 ++ .../precompiles/EcPairingCallCounter.java | 23 +++++ ...eCall.java => EcPairingEffectiveCall.java} | 8 +- .../precompiles/EcPairingMillerLoop.java | 4 +- .../precompiles/EcRecoverCallCounter.java | 23 +++++ .../precompiles/EcRecoverEffectiveCall.java | 6 ++ .../limits/precompiles/ModExpCallCounter.java | 23 +++++ .../{ModexpEffectiveCall.java => Modexp.java} | 8 +- .../limits/precompiles/Rip160Blocks.java | 6 ++ .../limits/precompiles/Rip160CallCounter.java | 23 +++++ .../limits/precompiles/Sha256Blocks.java | 6 ++ .../limits/precompiles/Sha256CallCounter.java | 23 +++++ .../zktracer/module/rlp/addr/RlpAddr.java | 2 +- .../linea/zktracer/module/rom/Rom.java | 8 +- .../linea/zktracer/module/romLex/RomLex.java | 23 +++-- .../src/main/resources/spillings.toml | 21 +++-- gradle.properties | 2 +- 32 files changed, 592 insertions(+), 51 deletions(-) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashData.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashInfo.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/AbstractCallCounter.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fCallCounter.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddCallCounter.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulCallCounter.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallCounter.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/{EcPairingCallEffectiveCall.java => EcPairingEffectiveCall.java} (92%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverCallCounter.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModExpCallCounter.java rename arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/{ModexpEffectiveCall.java => Modexp.java} (96%) create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160CallCounter.java create mode 100644 arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256CallCounter.java diff --git a/CHANGELOG.md b/CHANGELOG.md index decb803408..aa2b1c4d2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog -## 0.1.4-SNAPSHOT +## 0.1.4-test +Temporary line counting release for testnet. + +* count stack temporary impl: make loginfo counts closer to Geth [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only) +-- +* fix: `Bytes.toUnsignedInteger` [#484](https://github.com/ConsenSys/besu-sequencer-plugins/pull/484) +* perf: delay computations at trace time [#483](https://github.com/ConsenSys/besu-sequencer-plugins/pull/483) ## 0.1.3 - perf: improve `StackedSet` performances [#466](https://github.com/ConsenSys/besu-sequencer-plugins/pull/466) diff --git a/acceptance-tests/src/test/resources/moduleLimits.toml b/acceptance-tests/src/test/resources/moduleLimits.toml index c5a6067f51..5a5d830997 100644 --- a/acceptance-tests/src/test/resources/moduleLimits.toml +++ b/acceptance-tests/src/test/resources/moduleLimits.toml @@ -25,6 +25,8 @@ MXP = 524288 PHONEY_RLP = 65536 # can probably get lower PUB_HASH = 32768 PUB_HASH_INFO = 8192 +OLD_PUB_HASH = 32768 +OLD_PUB_HASH_INFO = 8192 PUB_LOG = 16384 PUB_LOG_INFO = 16384 RLP = 128 @@ -63,4 +65,13 @@ PRECOMPILE_ECADD_EFFECTIVE_CALL = 10000 PRECOMPILE_ECMUL_EFFECTIVE_CALL = 10000 PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 10000 PRECOMPILE_ECPAIRING_MILLER_LOOP = 10000 -PRECOMPILE_BLAKE2F_ROUNDS = 512 \ No newline at end of file +PRECOMPILE_BLAKE2F_ROUNDS = 512 + +PRECOMPILE_BLAKE2F = 512 +PRECOMPILE_ECADD = 512 +PRECOMPILE_ECMUL = 512 +PRECOMPILE_ECPAIRING = 512 +PRECOMPILE_ECRECOVER = 512 +PRECOMPILE_MODEXP = 512 +PRECOMPILE_RIPEMD = 512 +PRECOMPILE_SHA2 = 512 \ No newline at end of file diff --git a/acceptance-tests/src/test/resources/noModuleLimits.toml b/acceptance-tests/src/test/resources/noModuleLimits.toml index aac211dc3b..99656d01c3 100644 --- a/acceptance-tests/src/test/resources/noModuleLimits.toml +++ b/acceptance-tests/src/test/resources/noModuleLimits.toml @@ -25,6 +25,8 @@ MXP = 524288 PHONEY_RLP = 65536 # can probably get lower PUB_HASH = 32768 PUB_HASH_INFO = 8192 +OLD_PUB_HASH = 32768 +OLD_PUB_HASH_INFO = 8192 PUB_LOG = 16384 PUB_LOG_INFO = 16384 RLP = 128 @@ -63,4 +65,13 @@ PRECOMPILE_ECADD_EFFECTIVE_CALL = 10000 PRECOMPILE_ECMUL_EFFECTIVE_CALL = 10000 PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 10000 PRECOMPILE_ECPAIRING_MILLER_LOOP = 10000 -PRECOMPILE_BLAKE2F_ROUNDS = 512 \ No newline at end of file +PRECOMPILE_BLAKE2F_ROUNDS = 512 + +PRECOMPILE_BLAKE2F = 512 +PRECOMPILE_ECADD = 512 +PRECOMPILE_ECMUL = 512 +PRECOMPILE_ECPAIRING = 512 +PRECOMPILE_ECRECOVER = 512 +PRECOMPILE_MODEXP = 512 +PRECOMPILE_RIPEMD = 512 +PRECOMPILE_SHA2 = 512 \ No newline at end of file diff --git a/acceptance-tests/src/test/resources/txOverflowModuleLimits.toml b/acceptance-tests/src/test/resources/txOverflowModuleLimits.toml index a2db09056f..0ca392793e 100644 --- a/acceptance-tests/src/test/resources/txOverflowModuleLimits.toml +++ b/acceptance-tests/src/test/resources/txOverflowModuleLimits.toml @@ -26,6 +26,8 @@ MXP = 20 PHONEY_RLP = 65536 # can probably get lower PUB_HASH = 32768 PUB_HASH_INFO = 8192 +OLD_PUB_HASH = 32768 +OLD_PUB_HASH_INFO = 8192 PUB_LOG = 16384 PUB_LOG_INFO = 16384 RLP = 128 @@ -64,4 +66,13 @@ PRECOMPILE_ECADD_EFFECTIVE_CALL = 10000 PRECOMPILE_ECMUL_EFFECTIVE_CALL = 10000 PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 10000 PRECOMPILE_ECPAIRING_MILLER_LOOP = 10000 -PRECOMPILE_BLAKE2F_ROUNDS = 512 \ No newline at end of file +PRECOMPILE_BLAKE2F_ROUNDS = 512 + +PRECOMPILE_BLAKE2F = 512 +PRECOMPILE_ECADD = 512 +PRECOMPILE_ECMUL = 512 +PRECOMPILE_ECPAIRING = 512 +PRECOMPILE_ECRECOVER = 512 +PRECOMPILE_MODEXP = 512 +PRECOMPILE_RIPEMD = 512 +PRECOMPILE_SHA2 = 512 \ No newline at end of file diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java index 4a78d9c33b..159a655e17 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java @@ -27,6 +27,9 @@ /** Utility class that provides various helper methods. */ public class Util { + public static long ceilingTo(long x, long anchor) { + return (x + anchor - 1) / anchor; + } /** * Converts the bits of an unsigned byte into an array of Booleans. 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 174ae7fce1..6caeac59a4 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 @@ -40,16 +40,18 @@ import net.consensys.linea.zktracer.module.hub.fragment.*; import net.consensys.linea.zktracer.module.hub.fragment.misc.MiscFragment; import net.consensys.linea.zktracer.module.hub.section.*; +import net.consensys.linea.zktracer.module.legacy.hash.HashData; +import net.consensys.linea.zktracer.module.legacy.hash.HashInfo; import net.consensys.linea.zktracer.module.limits.Keccak; import net.consensys.linea.zktracer.module.limits.L2Block; import net.consensys.linea.zktracer.module.limits.L2L1Logs; import net.consensys.linea.zktracer.module.limits.precompiles.Blake2fRounds; import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingCallEffectiveCall; +import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingEffectiveCall; import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoop; import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall; -import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall; +import net.consensys.linea.zktracer.module.limits.precompiles.Modexp; import net.consensys.linea.zktracer.module.limits.precompiles.Rip160Blocks; import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks; import net.consensys.linea.zktracer.module.logData.LogData; @@ -181,15 +183,29 @@ public void addTraceSection(TraceSection section) { private final RomLex romLex; private final TxnData txnData; private final Trm trm = new Trm(); - private final ModexpEffectiveCall modexp; private final Stp stp = new Stp(this, wcp, mod); private final L2Block l2Block = new L2Block(); + private final HashInfo hashInfo; + private final HashData hashData; + + // Precompiles stuff + Blake2fRounds blake2f; + EcAddEffectiveCall ecAdd; + EcMulEffectiveCall ecMul; + EcPairingEffectiveCall ecPairing; + EcRecoverEffectiveCall ecRecover; + Modexp modexp; + Rip160Blocks rip160; + Sha256Blocks sha256; private final List modules; /* Those modules are not traced, we just compute the number of calls to those precompile to meet the prover limits */ private final List precompileLimitModules; public Hub() { + // + // Module + // this.pch = new PlatformController(this); this.mmu = new Mmu(this.callStack); this.mxp = new Mxp(this); @@ -198,24 +214,46 @@ public Hub() { this.rlpTxn = new RlpTxn(this.romLex); this.txnData = new TxnData(this, this.romLex, this.wcp); this.ecData = new EcData(this, this.wcp, this.ext); + this.hashData = new HashData(this); + this.hashInfo = new HashInfo(this); + + // + // Precompiles + // + this.blake2f = new Blake2fRounds(this); + this.ecAdd = new EcAddEffectiveCall(this); + this.ecMul = new EcMulEffectiveCall(this); + this.ecPairing = new EcPairingEffectiveCall(this); + this.ecRecover = new EcRecoverEffectiveCall(this); + this.modexp = new Modexp(this); + this.rip160 = new Rip160Blocks(this); + this.sha256 = new Sha256Blocks(this); - final EcRecoverEffectiveCall ecRec = new EcRecoverEffectiveCall(this); - this.modexp = new ModexpEffectiveCall(this); - final EcPairingCallEffectiveCall ecpairingCall = new EcPairingCallEffectiveCall(this); this.precompileLimitModules = List.of( - new Sha256Blocks(this), - ecRec, - new Rip160Blocks(this), + this.blake2f, + this.blake2f.callCounter(), + this.ecAdd, + this.ecAdd.callCounter(), + this.ecMul, + this.ecMul.callCounter(), + this.ecPairing, + this.ecPairing.callCounter(), + new EcPairingMillerLoop(this.ecPairing), + this.ecRecover, + this.ecRecover.callCounter(), this.modexp, - new EcAddEffectiveCall(this), - new EcMulEffectiveCall(this), - ecpairingCall, - new EcPairingMillerLoop(ecpairingCall), - new Blake2fRounds(this), + this.modexp.callCounter(), + this.rip160, + this.rip160.callCounter(), + this.sha256, + this.sha256.callCounter(), + // Block level limits + this.hashData, + this.hashInfo, this.l2Block, - new Keccak(this, ecRec, this.l2Block), + new Keccak(this, this.ecRecover, this.l2Block), new L2L1Logs(this.l2Block)); this.modules = @@ -237,7 +275,7 @@ public Hub() { this.rom, this.shf, this.trm, - this.txnData, + // this.txnData, this.stp, this.wcp), this.precompileLimitModules.stream()) @@ -249,11 +287,15 @@ public Hub() { */ public List getModulesToTrace() { return List.of( + // // Reference tables + // new BinRt(), new InstructionDecoder(), new ShfRt(), + // // Modules + // this, this.add, this.bin, @@ -271,7 +313,7 @@ public List getModulesToTrace() { this.romLex, this.shf, this.stp, - this.txnData, + // this.txnData, this.wcp); } @@ -296,8 +338,10 @@ public List getModulesToCount() { this.rom, this.shf, this.trm, - this.txnData, - this.wcp), + // this.txnData, + this.wcp, + this.hashData, + this.hashInfo), this.precompileLimitModules.stream()) .toList(); } @@ -508,7 +552,7 @@ void triggerModules(MessageFrame frame) { // TODO: this.oob.tracePreOpcode(frame); } if (this.pch.signals().stp()) { - this.stp.tracePreOpcode(frame); + // this.stp.tracePreOpcode(frame); } if (this.pch.signals().exp()) { this.modexp.tracePreOpcode(frame); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java index 2745fc4cb0..f26dd8c9e2 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java @@ -118,8 +118,8 @@ public void commit(Trace hubTrace) { */ public int lineCount() { if (this.cachedLineCount == 0) { - for (TraceSection s : trace) { - this.cachedLineCount += s.getLines().size(); + for (TraceSection section : this.trace) { + this.cachedLineCount += section.getStackRowsCounter(); } } return this.cachedLineCount; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashData.java new file mode 100644 index 0000000000..83a70ecd53 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashData.java @@ -0,0 +1,77 @@ +/* + * 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.legacy.hash; + +import static net.consensys.linea.zktracer.module.Util.ceilingTo; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.List; + +import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.module.Module; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.hyperledger.besu.evm.frame.MessageFrame; +import org.hyperledger.besu.evm.internal.Words; + +@RequiredArgsConstructor +public class HashData implements Module { + private final Hub hub; + private final Deque state = new ArrayDeque<>(); + + @Override + public String moduleKey() { + return "PUB_HASH"; + } + + @Override + public void enterTransaction() { + this.state.push(0); + } + + @Override + public void popTransaction() { + this.state.pop(); + } + + @Override + public int lineCount() { + return this.state.stream().mapToInt(x -> x).sum(); + } + + @Override + public List columnsHeaders() { + throw new IllegalStateException("should never be called"); + } + + private void add(int x) { + this.state.push(this.state.pop() + x); + } + + @Override + public void tracePreOpcode(MessageFrame frame) { + final OpCode opCode = hub.opCode(); + if (opCode == OpCode.CREATE2 || opCode == OpCode.SHA3) { + if (this.hub.pch().exceptions().none()) { + final long size = Words.clampedToLong(frame.getStackItem(1)); + final long paddedSize = ceilingTo(size, 16); + this.add((int) (paddedSize / 16)); + } + } + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashInfo.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashInfo.java new file mode 100644 index 0000000000..60c4a48b81 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/legacy/hash/HashInfo.java @@ -0,0 +1,72 @@ +/* + * 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.legacy.hash; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.List; + +import lombok.RequiredArgsConstructor; +import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.module.Module; +import net.consensys.linea.zktracer.module.hub.Hub; +import net.consensys.linea.zktracer.opcode.OpCode; +import org.hyperledger.besu.evm.frame.MessageFrame; + +@RequiredArgsConstructor +public class HashInfo implements Module { + private final Hub hub; + private final Deque state = new ArrayDeque<>(); + + @Override + public String moduleKey() { + return "PUB_HASH_INFO"; + } + + @Override + public void enterTransaction() { + this.state.push(0); + } + + @Override + public void popTransaction() { + this.state.pop(); + } + + @Override + public int lineCount() { + return this.state.stream().mapToInt(x -> x).sum(); + } + + @Override + public List columnsHeaders() { + throw new IllegalStateException("should never be called"); + } + + private void add(int x) { + this.state.push(this.state.pop() + x); + } + + @Override + public void tracePreOpcode(MessageFrame frame) { + final OpCode opCode = hub.opCode(); + if (opCode == OpCode.CREATE2 || opCode == OpCode.SHA3) { + if (this.hub.pch().exceptions().none()) { + this.add(1); + } + } + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/AbstractCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/AbstractCallCounter.java new file mode 100644 index 0000000000..17bae8215e --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/AbstractCallCounter.java @@ -0,0 +1,57 @@ +/* + * 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.limits.precompiles; + +import java.util.ArrayDeque; +import java.util.Deque; +import java.util.List; + +import net.consensys.linea.zktracer.ColumnHeader; +import net.consensys.linea.zktracer.module.Module; +import org.apache.commons.lang3.NotImplementedException; + +public class AbstractCallCounter implements Module { + private final Deque callCount = new ArrayDeque<>(); + + @Override + public String moduleKey() { + throw new NotImplementedException("must be implemented by derived class"); + } + + @Override + public void enterTransaction() { + this.callCount.push(0); + } + + @Override + public void popTransaction() { + this.callCount.pop(); + } + + @Override + public int lineCount() { + return this.callCount.stream().mapToInt(x -> x).sum(); + } + + public void tick() { + this.callCount.push(this.callCount.pop() + 1); + } + + @Override + public List columnsHeaders() { + throw new IllegalStateException("should never be called"); + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fCallCounter.java new file mode 100644 index 0000000000..c33ea10475 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fCallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.limits.precompiles; + +public class Blake2fCallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_BLAKE2F"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java index 035d748713..f631772c17 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Blake2fRounds.java @@ -30,9 +30,14 @@ @RequiredArgsConstructor public final class Blake2fRounds implements Module { - final Hub hub; + private final Hub hub; + private final Blake2fCallCounter blake2fCallCounter = new Blake2fCallCounter(); private final Stack counts = new Stack<>(); + public Module callCounter() { + return this.blake2fCallCounter; + } + @Override public String moduleKey() { return "PRECOMPILE_BLAKE2F_ROUNDS"; @@ -56,6 +61,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.BLAKE2B_F_COMPRESSION)) { + this.blake2fCallCounter.tick(); long length = 0; long offset = 0; switch (opCode) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddCallCounter.java new file mode 100644 index 0000000000..06037849f8 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddCallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.limits.precompiles; + +public class EcAddCallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_ECADD"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java index 8ddea82976..497d035cb5 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcAddEffectiveCall.java @@ -31,8 +31,13 @@ @RequiredArgsConstructor public final class EcAddEffectiveCall implements Module { private final Hub hub; + private final EcAddCallCounter ecAddCallCounter = new EcAddCallCounter(); private final Stack counts = new Stack<>(); + public Module callCounter() { + return this.ecAddCallCounter; + } + @Override public String moduleKey() { return "PRECOMPILE_ECADD_EFFECTIVE_CALL"; @@ -58,6 +63,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.ALTBN128_ADD)) { + this.ecAddCallCounter.tick(); final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); if (gasPaid >= PRECOMPILE_GAS_FEE) { this.counts.push(this.counts.pop() + 1); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulCallCounter.java new file mode 100644 index 0000000000..3e5bf0fd77 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulCallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.limits.precompiles; + +public class EcMulCallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_ECMUL"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java index ac45cedc1f..29f19b3f57 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcMulEffectiveCall.java @@ -1,4 +1,5 @@ /* + * Copyright ConsenSys Inc. * Copyright Consensys Software Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with @@ -31,8 +32,13 @@ @RequiredArgsConstructor public final class EcMulEffectiveCall implements Module { private final Hub hub; + private final EcMulCallCounter ecMulCallCounter = new EcMulCallCounter(); private final Stack counts = new Stack<>(); + public Module callCounter() { + return this.ecMulCallCounter; + } + @Override public String moduleKey() { return "PRECOMPILE_ECMUL_EFFECTIVE_CALL"; @@ -58,6 +64,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.ALTBN128_MUL)) { + this.ecMulCallCounter.tick(); final long gasPaid = Words.clampedToLong(frame.getStackItem(0)); if (gasPaid >= PRECOMPILE_GAS_FEE) { this.counts.push(this.counts.pop() + 1); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallCounter.java new file mode 100644 index 0000000000..4b41000913 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.module.limits.precompiles; + +public final class EcPairingCallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_ECPAIRING"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingEffectiveCall.java similarity index 92% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingEffectiveCall.java index 71a8efca72..78c1a98218 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingCallEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingEffectiveCall.java @@ -32,13 +32,18 @@ @Slf4j @RequiredArgsConstructor -public final class EcPairingCallEffectiveCall implements Module { +public final class EcPairingEffectiveCall implements Module { private final Hub hub; + private final EcPairingCallCounter ecPairingCallCounter = new EcPairingCallCounter(); @Getter private final Stack counts = new Stack<>(); private static final int PRECOMPILE_BASE_GAS_FEE = 45000; // cf EIP-1108 private static final int PRECOMPILE_MILLER_LOOP_GAS_FEE = 34000; // cf EIP-1108 private static final int ECPAIRING_NB_BYTES_PER_MILLER_LOOP = 192; + public Module callCounter() { + return this.ecPairingCallCounter; + } + @Override public String moduleKey() { return "PRECOMPILE_ECPAIRING_EFFECTIVE_CALL"; @@ -62,6 +67,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.ALTBN128_PAIRING)) { + this.ecPairingCallCounter.tick(); long length = 0; switch (opCode) { case CALL, CALLCODE -> length = Words.clampedToLong(frame.getStackItem(4)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java index ff0fd622fd..f1de3d2071 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcPairingMillerLoop.java @@ -22,9 +22,9 @@ import net.consensys.linea.zktracer.module.Module; public final class EcPairingMillerLoop implements Module { - private final EcPairingCallEffectiveCall ecpairingCall; + private final EcPairingEffectiveCall ecpairingCall; - public EcPairingMillerLoop(EcPairingCallEffectiveCall ecpairingCall) { + public EcPairingMillerLoop(EcPairingEffectiveCall ecpairingCall) { this.ecpairingCall = ecpairingCall; } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverCallCounter.java new file mode 100644 index 0000000000..81e741c1ec --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverCallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.limits.precompiles; + +public class EcRecoverCallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_ECRECOVER"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java index 904880f120..032f083a3b 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/EcRecoverEffectiveCall.java @@ -35,8 +35,13 @@ @RequiredArgsConstructor public final class EcRecoverEffectiveCall implements Module { private final Hub hub; + private final EcRecoverCallCounter ecRecoverCallCounter = new EcRecoverCallCounter(); private final Stack counts = new Stack<>(); + public Module callCounter() { + return this.ecRecoverCallCounter; + } + @Override public String moduleKey() { return "PRECOMPILE_ECRECOVER_EFFECTIVE_CALL"; @@ -66,6 +71,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.ECREC)) { + this.ecRecoverCallCounter.tick(); long length = 0; long offset = 0; switch (opCode) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModExpCallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModExpCallCounter.java new file mode 100644 index 0000000000..fdb1f1d825 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModExpCallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.module.limits.precompiles; + +public final class ModExpCallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_MODEXP"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Modexp.java similarity index 96% rename from arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java rename to arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Modexp.java index 50af40e1fc..d72f91f7ec 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/ModexpEffectiveCall.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Modexp.java @@ -35,12 +35,17 @@ @Slf4j @RequiredArgsConstructor -public class ModexpEffectiveCall implements Module { +public class Modexp implements Module { private final Hub hub; + public final ModExpCallCounter modExpCallCounter = new ModExpCallCounter(); private final Stack counts = new Stack<>(); private static final BigInteger PROVER_MAX_INPUT_BIT_SIZE = BigInteger.valueOf(4096); private static final int EVM_WORD_SIZE = 32; + public Module callCounter() { + return this.modExpCallCounter; + } + @Override public String moduleKey() { return "PRECOMPILE_MODEXP_EFFECTIVE_CALL"; @@ -64,6 +69,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.MODEXP)) { + this.modExpCallCounter.tick(); long length = 0; long offset = 0; switch (opCode) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java index aa4b5c328a..e4092cecad 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160Blocks.java @@ -31,6 +31,7 @@ @RequiredArgsConstructor public final class Rip160Blocks implements Module { private final Hub hub; + private final Rip160CallCounter rip160CallCounter = new Rip160CallCounter(); private final Stack counts = new Stack<>(); @Override @@ -45,6 +46,10 @@ public String moduleKey() { private static final int RIPEMD160_LENGTH_APPEND = 64; private static final int RIPEMD160_ND_PADDED_ONE = 1; + public Module callCounter() { + return this.rip160CallCounter; + } + @Override public void enterTransaction() { counts.push(0); @@ -63,6 +68,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.RIPEMD160)) { + this.rip160CallCounter.tick(); long dataByteLength = 0; switch (opCode) { case CALL, CALLCODE -> dataByteLength = Words.clampedToLong(frame.getStackItem(4)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160CallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160CallCounter.java new file mode 100644 index 0000000000..b16ee2f604 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Rip160CallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.module.limits.precompiles; + +public final class Rip160CallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_RIPEMD"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java index 4fba3b5089..3437f61964 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256Blocks.java @@ -31,6 +31,7 @@ @RequiredArgsConstructor public final class Sha256Blocks implements Module { private final Hub hub; + private final Sha256CallCounter sha256CallCounter = new Sha256CallCounter(); private final Stack counts = new Stack<>(); @Override @@ -45,6 +46,10 @@ public String moduleKey() { private static final int SHA256_PADDING_LENGTH = 64; private static final int SHA256_NB_PADDED_ONE = 1; + public Module callCounter() { + return this.sha256CallCounter; + } + @Override public void enterTransaction() { counts.push(0); @@ -63,6 +68,7 @@ public void tracePreOpcode(MessageFrame frame) { case CALL, STATICCALL, DELEGATECALL, CALLCODE -> { final Address target = Words.toAddress(frame.getStackItem(1)); if (target.equals(Address.SHA256)) { + this.sha256CallCounter.tick(); long dataByteLength = 0; switch (opCode) { case CALL, CALLCODE -> dataByteLength = Words.clampedToLong(frame.getStackItem(4)); diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256CallCounter.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256CallCounter.java new file mode 100644 index 0000000000..20a2e53943 --- /dev/null +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/limits/precompiles/Sha256CallCounter.java @@ -0,0 +1,23 @@ +/* + * 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.module.limits.precompiles; + +public final class Sha256CallCounter extends AbstractCallCounter { + @Override + public String moduleKey() { + return "PRECOMPILE_SHA2"; + } +} diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java index 62a5547133..15c7503631 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rlp/addr/RlpAddr.java @@ -294,7 +294,7 @@ public int lineCount() { for (RlpAddrChunk chunk : this.chunkList) { traceRowSize += chunkRowSize(chunk); } - return traceRowSize; + return 2 * (traceRowSize + 1); // TODO: temporary hack for Geth/Besu } @Override diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java index 6c7aed7742..8c94a2eb5a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/rom/Rom.java @@ -62,15 +62,11 @@ public int lineCount() { for (RomChunk chunk : this.romLex.chunks) { traceRowSize += chunkRowSize(chunk); } - return traceRowSize; + return traceRowSize + 32 * this.romLex.emptyContractsCount.stream().mapToInt(x -> x).sum(); } public int chunkRowSize(RomChunk chunk) { - final int nPaddingRow = 32; - final int codeSize = chunk.byteCode().size(); - final int nbSlice = (codeSize + (LLARGE - 1)) / LLARGE; - - return LLARGE * nbSlice + nPaddingRow; + return chunk.byteCode().size(); } private void traceChunk(RomChunk chunk, int cfi, int cfiInfty, Trace trace) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomLex.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomLex.java index 0c82b09f2b..39239ee02f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomLex.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/romLex/RomLex.java @@ -20,8 +20,10 @@ import static org.hyperledger.besu.evm.internal.Words.clampedToLong; import java.nio.MappedByteBuffer; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Comparator; +import java.util.Deque; import java.util.List; import java.util.Optional; @@ -47,6 +49,7 @@ public class RomLex implements Module { public int codeIdentifierBeforeLexOrder = 0; public final StackedSet chunks = new StackedSet<>(); + public final Deque emptyContractsCount = new ArrayDeque<>(); public final List sortedChunks = new ArrayList<>(); private Bytes byteCode = Bytes.EMPTY; private Address address = Address.ZERO; @@ -87,11 +90,13 @@ public RomLex(Hub hub) { @Override public void enterTransaction() { this.chunks.enter(); + this.emptyContractsCount.push(0); } @Override public void popTransaction() { this.chunks.pop(); + this.emptyContractsCount.pop(); } public int getCFIById(int value) { @@ -133,7 +138,7 @@ public void traceStartTx(WorldView worldView, Transaction tx) { tx.getTo() .map(worldView::get) .map(AccountState::getCode) - .ifPresent( + .ifPresentOrElse( code -> { codeIdentifierBeforeLexOrder += 1; int depNumber = hub.conflation().deploymentInfo().number(tx.getTo().get()); @@ -148,7 +153,8 @@ public void traceStartTx(WorldView worldView, Transaction tx) { false, codeIdentifierBeforeLexOrder, code)); - }); + }, + () -> this.emptyContractsCount.push(this.emptyContractsCount.pop() + 1)); } @Override @@ -183,7 +189,7 @@ public void tracePreOpcode(MessageFrame frame) { final Bytes code = frame.shadowReadMemory(offset, length); final boolean depStatus = hub.conflation().deploymentInfo().isDeploying(frame.getContractAddress()); - if (!code.isEmpty() && depStatus) { + if (depStatus) { codeIdentifierBeforeLexOrder += 1; int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress()); this.chunks.add( @@ -205,7 +211,7 @@ public void tracePreOpcode(MessageFrame frame) { final int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress()); Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)) .map(AccountState::getCode) - .ifPresent( + .ifPresentOrElse( byteCode -> { codeIdentifierBeforeLexOrder += 1; this.chunks.add( @@ -217,7 +223,8 @@ public void tracePreOpcode(MessageFrame frame) { false, codeIdentifierBeforeLexOrder, byteCode)); - }); + }, + () -> this.emptyContractsCount.push(this.emptyContractsCount.pop() + 1)); } case EXTCODECOPY -> { @@ -231,7 +238,7 @@ public void tracePreOpcode(MessageFrame frame) { final int depNumber = hub.conflation().deploymentInfo().number(frame.getContractAddress()); Optional.ofNullable(frame.getWorldUpdater().get(calledAddress)) .map(AccountState::getCode) - .ifPresent( + .ifPresentOrElse( byteCode -> { if (!byteCode.isEmpty()) { codeIdentifierBeforeLexOrder += 1; @@ -245,7 +252,8 @@ public void tracePreOpcode(MessageFrame frame) { codeIdentifierBeforeLexOrder, byteCode)); } - }); + }, + () -> this.emptyContractsCount.push(this.emptyContractsCount.pop() + 1)); } } } @@ -269,6 +277,7 @@ public void tracePostExecution(MessageFrame frame, Operation.OperationResult ope this.byteCode)); } } + this.byteCode = Bytes.EMPTY; } private void traceChunk( diff --git a/arithmetization/src/main/resources/spillings.toml b/arithmetization/src/main/resources/spillings.toml index f87ddc06f6..e33683f944 100644 --- a/arithmetization/src/main/resources/spillings.toml +++ b/arithmetization/src/main/resources/spillings.toml @@ -5,7 +5,9 @@ BIN = 16 EC_DATA = 12 EXT = 8 PUB_HASH = 0 +OLD_PUB_HASH = 0 PUB_HASH_INFO = 0 +OLD_PUB_HASH_INFO = 0 HUB = 2 PUB_LOG = 1 PUB_LOG_INFO = 5 @@ -24,18 +26,27 @@ STP = 4 TRM = 7 WCP = 16 +PRECOMPILE_ECRECOVER = 0 PRECOMPILE_ECRECOVER_EFFECTIVE_CALL = 0 -PRECOMPILE_SHA2_BLOCKS = 0 -PRECOMPILE_RIPEMD_BLOCKS = 0 +PRECOMPILE_SHA2 = 0 +PRECOMPILE_SHA2_BLOCKS = 0 +PRECOMPILE_SHA2_EFFECTIVE_CALL = 0 PRECOMPILE_IDENTITY = 0 +PRECOMPILE_MODEXP = 0 PRECOMPILE_MODEXP_EFFECTIVE_CALL = 0 +PRECOMPILE_ECADD = 0 PRECOMPILE_ECADD_EFFECTIVE_CALL = 0 +PRECOMPILE_ECMUL = 0 PRECOMPILE_ECMUL_EFFECTIVE_CALL = 0 +PRECOMPILE_ECPAIRING = 0 PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 0 PRECOMPILE_ECPAIRING_MILLER_LOOP = 0 -PRECOMPILE_BLAKE2F_ROUNDS = 0 - +PRECOMPILE_BLAKE2F = 0 +PRECOMPILE_BLAKE2F_ROUNDS = 0 +PRECOMPILE_RIPEMD = 0 +PRECOMPILE_RIPEMD_EFFECTIVE_CALL = 0 +PRECOMPILE_RIPEMD_BLOCKS = 0 BLOCK_TX = 0 BLOCK_L2L1LOGS = 0 BLOCK_KECCAK = 0 -BLOCK_L1SIZE = 0 \ No newline at end of file +BLOCK_L1SIZE = 0 diff --git a/gradle.properties b/gradle.properties index cbdb4c243d..ce170008f0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -releaseVersion=0.1.4-SNAPSHOT +releaseVersion=0.1.4-test besuVersion=23.10.4-SNAPSHOT besuArtifactGroup=io.consensys.linea-besu distributionIdentifier=besu-sequencer-plugins