Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp: geth counting compatibility #459

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Testing pre-release from branch test-release/v0.1.4-test2
* revert make loginfo counts closer to Geth
* head: disable stp & txndata

=======
>>>>>>> 820918a3 (temp: geth-compatibily hacks)
## 0.1.4-test
Temporary line counting release for testnet.

Expand Down
13 changes: 12 additions & 1 deletion acceptance-tests/src/test/resources/moduleLimits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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
Expand Down Expand Up @@ -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
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
13 changes: 12 additions & 1 deletion acceptance-tests/src/test/resources/noModuleLimits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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
Expand Down Expand Up @@ -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
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
13 changes: 12 additions & 1 deletion acceptance-tests/src/test/resources/txOverflowModuleLimits.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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
Expand Down Expand Up @@ -65,4 +67,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void traceEndBlock(final BlockHeader blockHeader, final BlockBody blockBo
}

@Override
public void tracePrepareTransaction(WorldView worldView, Transaction transaction) {
public void traceStartTransaction(WorldView worldView, Transaction transaction) {
hashOfLastTransactionTraced = transaction.getHash();
this.hub.traceStartTx(worldView, transaction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

/** Utility class that provides various helper methods. */
public class Util {
public static long roundedUpDivision(long x, long anchor) {
return (x + anchor - 1) / anchor;
}

/**
* Converts the bits of an unsigned byte into an array of Booleans.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ public void commit(List<MappedByteBuffer> buffers) {

@Override
public int lineCount() {
return this.chunks.lineCount();
return this.chunks.size() * 16;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,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;
Expand Down Expand Up @@ -184,9 +186,20 @@ 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;
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<Module> modules;
/* Those modules are not traced, we just compute the number of calls to those precompile to meet the prover limits */
Expand All @@ -204,24 +217,46 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) {
this.txnData = new TxnData(this, this.romLex, this.wcp);
this.ecData = new EcData(this, this.wcp, this.ext);
this.euc = new Euc(this.wcp);
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.refTableModules = List.of(new BinRt(), new InstructionDecoder(), new ShfRt());
Expand Down Expand Up @@ -257,32 +292,36 @@ public Hub(final Address l2l1ContractAddress, final Bytes l2l1Topic) {
* @return a list of all modules for which to generate traces
*/
public List<Module> getModulesToTrace() {
return Stream.concat(
this.refTableModules.stream(),
// Modules
Stream.of(
this,
this.romLex,
this.add,
this.bin,
this.ext,
// this.ecData, // TODO: not yet
this.euc,
this.logData,
this.logInfo,
this.mod,
this.modexp.data(),
this.mul,
this.mxp,
this.rlpAddr,
this.rlpTxn,
this.rlpTxrcpt,
this.rom,
this.shf,
this.stp,
this.txnData,
this.wcp))
.toList();
return List.of(
//
// Reference tables
//
new BinRt(),
new InstructionDecoder(),
new ShfRt(),
//
// Modules
//
this,
this.add,
this.bin,
this.ext,
// this.ecData, // TODO: not yet
this.euc,
this.logData,
this.logInfo,
this.mod,
this.mul,
this.mxp,
this.rlpAddr,
this.rlpTxn,
this.rlpTxrcpt,
this.rom,
this.romLex,
this.shf,
this.stp,
// this.txnData,
this.wcp);
}

public List<Module> getModulesToCount() {
Expand All @@ -307,8 +346,10 @@ public List<Module> getModulesToCount() {
this.rom,
this.shf,
this.trm,
this.txnData,
this.wcp),
// this.txnData,
this.wcp,
this.hashData,
this.hashInfo),
this.precompileLimitModules.stream())
.toList();
}
Expand Down Expand Up @@ -519,7 +560,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.roundedUpDivision;

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<Integer> 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<ColumnHeader> 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 int limbCount = (int) roundedUpDivision(size, 16);
this.add(limbCount);
}
}
}
}
Loading
Loading