Skip to content

Commit 208ccdf

Browse files
committed
temp: geth-compatibily hacks
1 parent fac8e0e commit 208ccdf

34 files changed

+598
-48
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Testing pre-release from branch test-release/v0.1.4-test2
5555
* revert make loginfo counts closer to Geth
5656
* head: disable stp & txndata
5757

58+
=======
59+
>>>>>>> 820918a3 (temp: geth-compatibily hacks)
5860
## 0.1.4-test
5961
Temporary line counting release for testnet.
6062

acceptance-tests/src/test/resources/moduleLimits.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ MXP = 524288
2626
PHONEY_RLP = 65536 # can probably get lower
2727
PUB_HASH = 32768
2828
PUB_HASH_INFO = 8192
29+
OLD_PUB_HASH = 32768
30+
OLD_PUB_HASH_INFO = 8192
2931
PUB_LOG = 16384
3032
PUB_LOG_INFO = 16384
3133
RLP = 128
@@ -64,4 +66,13 @@ PRECOMPILE_ECADD_EFFECTIVE_CALL = 10000
6466
PRECOMPILE_ECMUL_EFFECTIVE_CALL = 10000
6567
PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 10000
6668
PRECOMPILE_ECPAIRING_MILLER_LOOP = 10000
67-
PRECOMPILE_BLAKE2F_ROUNDS = 512
69+
PRECOMPILE_BLAKE2F_ROUNDS = 512
70+
71+
PRECOMPILE_BLAKE2F = 512
72+
PRECOMPILE_ECADD = 512
73+
PRECOMPILE_ECMUL = 512
74+
PRECOMPILE_ECPAIRING = 512
75+
PRECOMPILE_ECRECOVER = 512
76+
PRECOMPILE_MODEXP = 512
77+
PRECOMPILE_RIPEMD = 512
78+
PRECOMPILE_SHA2 = 512

acceptance-tests/src/test/resources/noModuleLimits.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ MXP = 524288
2626
PHONEY_RLP = 65536 # can probably get lower
2727
PUB_HASH = 32768
2828
PUB_HASH_INFO = 8192
29+
OLD_PUB_HASH = 32768
30+
OLD_PUB_HASH_INFO = 8192
2931
PUB_LOG = 16384
3032
PUB_LOG_INFO = 16384
3133
RLP = 128
@@ -64,4 +66,13 @@ PRECOMPILE_ECADD_EFFECTIVE_CALL = 10000
6466
PRECOMPILE_ECMUL_EFFECTIVE_CALL = 10000
6567
PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 10000
6668
PRECOMPILE_ECPAIRING_MILLER_LOOP = 10000
67-
PRECOMPILE_BLAKE2F_ROUNDS = 512
69+
PRECOMPILE_BLAKE2F_ROUNDS = 512
70+
71+
PRECOMPILE_BLAKE2F = 512
72+
PRECOMPILE_ECADD = 512
73+
PRECOMPILE_ECMUL = 512
74+
PRECOMPILE_ECPAIRING = 512
75+
PRECOMPILE_ECRECOVER = 512
76+
PRECOMPILE_MODEXP = 512
77+
PRECOMPILE_RIPEMD = 512
78+
PRECOMPILE_SHA2 = 512

acceptance-tests/src/test/resources/txOverflowModuleLimits.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ MXP = 20
2727
PHONEY_RLP = 65536 # can probably get lower
2828
PUB_HASH = 32768
2929
PUB_HASH_INFO = 8192
30+
OLD_PUB_HASH = 32768
31+
OLD_PUB_HASH_INFO = 8192
3032
PUB_LOG = 16384
3133
PUB_LOG_INFO = 16384
3234
RLP = 128
@@ -65,4 +67,13 @@ PRECOMPILE_ECADD_EFFECTIVE_CALL = 10000
6567
PRECOMPILE_ECMUL_EFFECTIVE_CALL = 10000
6668
PRECOMPILE_ECPAIRING_EFFECTIVE_CALL = 10000
6769
PRECOMPILE_ECPAIRING_MILLER_LOOP = 10000
68-
PRECOMPILE_BLAKE2F_ROUNDS = 512
70+
PRECOMPILE_BLAKE2F_ROUNDS = 512
71+
72+
PRECOMPILE_BLAKE2F = 512
73+
PRECOMPILE_ECADD = 512
74+
PRECOMPILE_ECMUL = 512
75+
PRECOMPILE_ECPAIRING = 512
76+
PRECOMPILE_ECRECOVER = 512
77+
PRECOMPILE_MODEXP = 512
78+
PRECOMPILE_RIPEMD = 512
79+
PRECOMPILE_SHA2 = 512

arithmetization/src/main/java/net/consensys/linea/zktracer/module/Util.java

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
/** Utility class that provides various helper methods. */
2929
public class Util {
30+
public static long ceilingTo(long x, long anchor) {
31+
return (x + anchor - 1) / anchor;
32+
}
3033

3134
/**
3235
* Converts the bits of an unsigned byte into an array of Booleans.

arithmetization/src/main/java/net/consensys/linea/zktracer/module/add/Add.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public void commit(List<MappedByteBuffer> buffers) {
7070

7171
@Override
7272
public int lineCount() {
73-
return this.chunks.lineCount();
73+
return this.chunks.size() * 16;
7474
}
7575
}

arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/Hub.java

+64-20
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@
4141
import net.consensys.linea.zktracer.module.hub.fragment.*;
4242
import net.consensys.linea.zktracer.module.hub.fragment.misc.MiscFragment;
4343
import net.consensys.linea.zktracer.module.hub.section.*;
44+
import net.consensys.linea.zktracer.module.legacy.hash.HashData;
45+
import net.consensys.linea.zktracer.module.legacy.hash.HashInfo;
4446
import net.consensys.linea.zktracer.module.limits.Keccak;
4547
import net.consensys.linea.zktracer.module.limits.L2Block;
4648
import net.consensys.linea.zktracer.module.limits.L2L1Logs;
4749
import net.consensys.linea.zktracer.module.limits.precompiles.Blake2fRounds;
4850
import net.consensys.linea.zktracer.module.limits.precompiles.EcAddEffectiveCall;
4951
import net.consensys.linea.zktracer.module.limits.precompiles.EcMulEffectiveCall;
50-
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingCallEffectiveCall;
52+
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingEffectiveCall;
5153
import net.consensys.linea.zktracer.module.limits.precompiles.EcPairingMillerLoop;
5254
import net.consensys.linea.zktracer.module.limits.precompiles.EcRecoverEffectiveCall;
53-
import net.consensys.linea.zktracer.module.limits.precompiles.ModexpEffectiveCall;
55+
import net.consensys.linea.zktracer.module.limits.precompiles.Modexp;
5456
import net.consensys.linea.zktracer.module.limits.precompiles.Rip160Blocks;
5557
import net.consensys.linea.zktracer.module.limits.precompiles.Sha256Blocks;
5658
import net.consensys.linea.zktracer.module.logData.LogData;
@@ -183,15 +185,29 @@ public void addTraceSection(TraceSection section) {
183185
private final RomLex romLex;
184186
private final TxnData txnData;
185187
private final Trm trm = new Trm();
186-
private final ModexpEffectiveCall modexp;
187188
private final Stp stp = new Stp(this, wcp, mod);
188189
private final L2Block l2Block = new L2Block();
190+
private final HashInfo hashInfo;
191+
private final HashData hashData;
192+
193+
// Precompiles stuff
194+
Blake2fRounds blake2f;
195+
EcAddEffectiveCall ecAdd;
196+
EcMulEffectiveCall ecMul;
197+
EcPairingEffectiveCall ecPairing;
198+
EcRecoverEffectiveCall ecRecover;
199+
Modexp modexp;
200+
Rip160Blocks rip160;
201+
Sha256Blocks sha256;
189202

190203
private final List<Module> modules;
191204
/* Those modules are not traced, we just compute the number of calls to those precompile to meet the prover limits */
192205
private final List<Module> precompileLimitModules;
193206

194207
public Hub() {
208+
//
209+
// Module
210+
//
195211
this.pch = new PlatformController(this);
196212
this.mmu = new Mmu(this.callStack);
197213
this.mxp = new Mxp(this);
@@ -201,24 +217,46 @@ public Hub() {
201217
this.txnData = new TxnData(this, this.romLex, this.wcp);
202218
this.ecData = new EcData(this, this.wcp, this.ext);
203219
this.euc = new Euc(this.wcp);
220+
this.hashData = new HashData(this);
221+
this.hashInfo = new HashInfo(this);
222+
223+
//
224+
// Precompiles
225+
//
226+
this.blake2f = new Blake2fRounds(this);
227+
this.ecAdd = new EcAddEffectiveCall(this);
228+
this.ecMul = new EcMulEffectiveCall(this);
229+
this.ecPairing = new EcPairingEffectiveCall(this);
230+
this.ecRecover = new EcRecoverEffectiveCall(this);
231+
this.modexp = new Modexp(this);
232+
this.rip160 = new Rip160Blocks(this);
233+
this.sha256 = new Sha256Blocks(this);
204234

205-
final EcRecoverEffectiveCall ecRec = new EcRecoverEffectiveCall(this);
206-
this.modexp = new ModexpEffectiveCall(this);
207-
final EcPairingCallEffectiveCall ecpairingCall = new EcPairingCallEffectiveCall(this);
208235
this.precompileLimitModules =
209236
List.of(
210-
new Sha256Blocks(this),
211-
ecRec,
212-
new Rip160Blocks(this),
237+
this.blake2f,
238+
this.blake2f.callCounter(),
239+
this.ecAdd,
240+
this.ecAdd.callCounter(),
241+
this.ecMul,
242+
this.ecMul.callCounter(),
243+
this.ecPairing,
244+
this.ecPairing.callCounter(),
245+
new EcPairingMillerLoop(this.ecPairing),
246+
this.ecRecover,
247+
this.ecRecover.callCounter(),
213248
this.modexp,
214-
new EcAddEffectiveCall(this),
215-
new EcMulEffectiveCall(this),
216-
ecpairingCall,
217-
new EcPairingMillerLoop(ecpairingCall),
218-
new Blake2fRounds(this),
249+
this.modexp.callCounter(),
250+
this.rip160,
251+
this.rip160.callCounter(),
252+
this.sha256,
253+
this.sha256.callCounter(),
254+
219255
// Block level limits
256+
this.hashData,
257+
this.hashInfo,
220258
this.l2Block,
221-
new Keccak(this, ecRec, this.l2Block),
259+
new Keccak(this, this.ecRecover, this.l2Block),
222260
new L2L1Logs(this.l2Block));
223261

224262
this.modules =
@@ -241,7 +279,7 @@ public Hub() {
241279
this.rom,
242280
this.shf,
243281
this.trm,
244-
this.txnData,
282+
// this.txnData,
245283
this.stp,
246284
this.wcp),
247285
this.precompileLimitModules.stream())
@@ -253,11 +291,15 @@ public Hub() {
253291
*/
254292
public List<Module> getModulesToTrace() {
255293
return List.of(
294+
//
256295
// Reference tables
296+
//
257297
new BinRt(),
258298
new InstructionDecoder(),
259299
new ShfRt(),
300+
//
260301
// Modules
302+
//
261303
this,
262304
this.add,
263305
this.bin,
@@ -276,7 +318,7 @@ public List<Module> getModulesToTrace() {
276318
this.romLex,
277319
this.shf,
278320
this.stp,
279-
this.txnData,
321+
// this.txnData,
280322
this.wcp);
281323
}
282324

@@ -302,8 +344,10 @@ public List<Module> getModulesToCount() {
302344
this.rom,
303345
this.shf,
304346
this.trm,
305-
this.txnData,
306-
this.wcp),
347+
// this.txnData,
348+
this.wcp,
349+
this.hashData,
350+
this.hashInfo),
307351
this.precompileLimitModules.stream())
308352
.toList();
309353
}
@@ -514,7 +558,7 @@ void triggerModules(MessageFrame frame) {
514558
// TODO: this.oob.tracePreOpcode(frame);
515559
}
516560
if (this.pch.signals().stp()) {
517-
this.stp.tracePreOpcode(frame);
561+
// this.stp.tracePreOpcode(frame);
518562
}
519563
if (this.pch.signals().exp()) {
520564
this.modexp.tracePreOpcode(frame);

arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/TxTrace.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public void commit(Trace hubTrace) {
118118
*/
119119
public int lineCount() {
120120
if (this.cachedLineCount == 0) {
121-
for (TraceSection s : trace) {
122-
this.cachedLineCount += s.getLines().size();
121+
for (TraceSection section : this.trace) {
122+
this.cachedLineCount += section.getStackRowsCounter();
123123
}
124124
}
125125
return this.cachedLineCount;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright ConsenSys AG.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
16+
package net.consensys.linea.zktracer.module.legacy.hash;
17+
18+
import static net.consensys.linea.zktracer.module.Util.ceilingTo;
19+
20+
import java.util.ArrayDeque;
21+
import java.util.Deque;
22+
import java.util.List;
23+
24+
import lombok.RequiredArgsConstructor;
25+
import net.consensys.linea.zktracer.ColumnHeader;
26+
import net.consensys.linea.zktracer.module.Module;
27+
import net.consensys.linea.zktracer.module.hub.Hub;
28+
import net.consensys.linea.zktracer.opcode.OpCode;
29+
import org.hyperledger.besu.evm.frame.MessageFrame;
30+
import org.hyperledger.besu.evm.internal.Words;
31+
32+
@RequiredArgsConstructor
33+
public class HashData implements Module {
34+
private final Hub hub;
35+
private final Deque<Integer> state = new ArrayDeque<>();
36+
37+
@Override
38+
public String moduleKey() {
39+
return "PUB_HASH";
40+
}
41+
42+
@Override
43+
public void enterTransaction() {
44+
this.state.push(0);
45+
}
46+
47+
@Override
48+
public void popTransaction() {
49+
this.state.pop();
50+
}
51+
52+
@Override
53+
public int lineCount() {
54+
return this.state.stream().mapToInt(x -> x).sum();
55+
}
56+
57+
@Override
58+
public List<ColumnHeader> columnsHeaders() {
59+
throw new IllegalStateException("should never be called");
60+
}
61+
62+
private void add(int x) {
63+
this.state.push(this.state.pop() + x);
64+
}
65+
66+
@Override
67+
public void tracePreOpcode(MessageFrame frame) {
68+
final OpCode opCode = hub.opCode();
69+
if (opCode == OpCode.CREATE2 || opCode == OpCode.SHA3) {
70+
if (this.hub.pch().exceptions().none()) {
71+
final long size = Words.clampedToLong(frame.getStackItem(1));
72+
final long paddedSize = ceilingTo(size, 16);
73+
this.add((int) (paddedSize / 16));
74+
}
75+
}
76+
}
77+
}

0 commit comments

Comments
 (0)