Skip to content

Commit

Permalink
temp: geth-compatibily hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Jan 10, 2024
1 parent 4c81fa0 commit 820918a
Show file tree
Hide file tree
Showing 35 changed files with 603 additions and 49 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
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 @@ -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.
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 @@ -183,15 +185,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<Module> modules;
/* Those modules are not traced, we just compute the number of calls to those precompile to meet the prover limits */
private final List<Module> precompileLimitModules;

public Hub() {
//
// Module
//
this.pch = new PlatformController(this);
this.mmu = new Mmu(this.callStack);
this.mxp = new Mxp(this);
Expand All @@ -201,24 +217,46 @@ public Hub() {
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.modules =
Expand All @@ -241,7 +279,7 @@ public Hub() {
this.rom,
this.shf,
this.trm,
this.txnData,
// this.txnData,
this.stp,
this.wcp),
this.precompileLimitModules.stream())
Expand All @@ -253,11 +291,15 @@ public Hub() {
*/
public List<Module> getModulesToTrace() {
return List.of(
//
// Reference tables
//
new BinRt(),
new InstructionDecoder(),
new ShfRt(),
//
// Modules
//
this,
this.add,
this.bin,
Expand All @@ -276,7 +318,7 @@ public List<Module> getModulesToTrace() {
this.romLex,
this.shf,
this.stp,
this.txnData,
// this.txnData,
this.wcp);
}

Expand All @@ -302,8 +344,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 @@ -514,7 +558,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.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<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 long paddedSize = ceilingTo(size, 16);
this.add((int) (paddedSize / 16));
}
}
}
}
Loading

0 comments on commit 820918a

Please sign in to comment.