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 5, 2024
1 parent e656ae0 commit 9c6d852
Show file tree
Hide file tree
Showing 32 changed files with 592 additions and 51 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 @@ -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
Expand Down Expand Up @@ -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
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 @@ -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
Expand Down Expand Up @@ -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
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 @@ -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
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
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 @@ -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;
Expand Down Expand Up @@ -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<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 @@ -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 =
Expand All @@ -237,7 +275,7 @@ public Hub() {
this.rom,
this.shf,
this.trm,
this.txnData,
// this.txnData,
this.stp,
this.wcp),
this.precompileLimitModules.stream())
Expand All @@ -249,11 +287,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 @@ -271,7 +313,7 @@ public List<Module> getModulesToTrace() {
this.romLex,
this.shf,
this.stp,
this.txnData,
// this.txnData,
this.wcp);
}

Expand All @@ -296,8 +338,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 @@ -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);
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 9c6d852

Please sign in to comment.