Skip to content

Commit 8fddd4c

Browse files
committed
Merge branch 'arith-dev' into gauravahuja/shomei-node
2 parents bba056d + 5f20fed commit 8fddd4c

File tree

72 files changed

+2041
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2041
-328
lines changed

.github/actions/setup-go-corset/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ runs:
99

1010
- name: Install Go Corset
1111
shell: bash
12-
run: go install github.com/consensys/go-corset/cmd/[email protected].3
12+
run: go install github.com/consensys/go-corset/cmd/[email protected].7

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ reference-tests/src/test/java/net/consensys/linea/generated/*
3737
arithmetization/bin/
3838
acceptance-tests/bin/
3939
reference-tests/bin/
40-
**/*Trace.java
40+
**/*Trace*.java
4141
**/*GlobalConstants.java

arithmetization/src/main/java/net/consensys/linea/corset/GoCorsetValidator.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package net.consensys.linea.corset;
1717

1818
import static net.consensys.linea.zktracer.ChainConfig.MAINNET_LONDON_TESTCONFIG;
19+
import static net.consensys.linea.zktracer.Trace.*;
1920

2021
import java.io.IOException;
2122
import java.nio.file.Files;
@@ -52,7 +53,7 @@ public class GoCorsetValidator extends AbstractExecutable {
5253
@Getter private boolean active = false;
5354

5455
/** Details chain configuration. */
55-
private ChainConfig chain;
56+
private final ChainConfig chain;
5657

5758
/**
5859
* Aggregation of all coverage reports generated by go-corset. If GOCORSET_COVERAGE is set, then
@@ -154,6 +155,16 @@ private List<String> buildCommandLine(Path traceFile, String zkEvmBin) {
154155
* @param options
155156
*/
156157
private void setChainConstants(List<String> options) {
158+
final int fork =
159+
switch (chain.fork) {
160+
case LONDON -> EVM_LONDON;
161+
// case PARIS -> EVM_PARIS;
162+
case SHANGHAI -> EVM_SHANGHAI;
163+
case CANCUN -> EVM_CANCUN;
164+
case PRAGUE -> EVM_PRAGUE;
165+
default -> throw new IllegalArgumentException("unknown fork \"" + chain.fork + "\"");
166+
};
167+
options.add("-SEVM_FORK=" + fork);
157168
if (chain != MAINNET_LONDON_TESTCONFIG) {
158169
options.add("-Sblockdata.GAS_LIMIT_MINIMUM=" + chain.gasLimitMinimum.toString());
159170
options.add("-Sblockdata.GAS_LIMIT_MAXIMUM=" + chain.gasLimitMaximum.toString());

arithmetization/src/main/java/net/consensys/linea/zktracer/ChainConfig.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,17 @@ public class ChainConfig {
3535
* Represents Linea mainnet as it stands today which enforces the block gas limit (currently two
3636
* billion). As the name suggest, this is only intended for testing purposes.
3737
*/
38-
public static final ChainConfig MAINNET_LONDON_TESTCONFIG =
39-
new ChainConfig(
40-
LONDON,
41-
LINEA_CHAIN_ID,
42-
true,
43-
BigInteger.valueOf(LINEA_GAS_LIMIT_MINIMUM),
44-
BigInteger.valueOf(LINEA_GAS_LIMIT_MAXIMUM),
45-
LineaL1L2BridgeSharedConfiguration.TEST_DEFAULT);
38+
public static final ChainConfig MAINNET_LONDON_TESTCONFIG = MAINNET_TESTCONFIG(LONDON);
4639

47-
/** Represents Ethereum mainnet for the purposes of running reference tests. */
48-
public static final ChainConfig ETHEREUM_LONDON =
49-
new ChainConfig(
50-
LONDON,
51-
1,
52-
false,
53-
BigInteger.valueOf(ETHEREUM_GAS_LIMIT_MINIMUM),
54-
ETHEREUM_GAS_LIMIT_MAXIMUM,
55-
LineaL1L2BridgeSharedConfiguration.TEST_DEFAULT);
40+
public static final ChainConfig MAINNET_TESTCONFIG(final Fork fork) {
41+
return new ChainConfig(
42+
fork,
43+
LINEA_CHAIN_ID,
44+
true,
45+
BigInteger.valueOf(LINEA_GAS_LIMIT_MINIMUM),
46+
BigInteger.valueOf(LINEA_GAS_LIMIT_MAXIMUM),
47+
LineaL1L2BridgeSharedConfiguration.TEST_DEFAULT);
48+
}
5649

5750
/**
5851
* Represents Linea mainnet prior to the block gas limit being enforced for the purposes of
@@ -162,4 +155,20 @@ public static ChainConfig FORK_LINEA_CHAIN(
162155
BigInteger.valueOf(LINEA_GAS_LIMIT_MAXIMUM),
163156
bridgeConfig);
164157
}
158+
159+
/**
160+
* Construct a suitable configuration representing a specific fork of Ethereum mainnet.
161+
*
162+
* @param fork
163+
* @return
164+
*/
165+
public static ChainConfig ETHEREUM_CHAIN(String fork) {
166+
return new ChainConfig(
167+
Fork.fromString(fork),
168+
1,
169+
false,
170+
BigInteger.valueOf(ETHEREUM_GAS_LIMIT_MINIMUM),
171+
ETHEREUM_GAS_LIMIT_MAXIMUM,
172+
LineaL1L2BridgeSharedConfiguration.TEST_DEFAULT);
173+
}
165174
}

arithmetization/src/main/java/net/consensys/linea/zktracer/Fork.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,36 @@
1717

1818
public enum Fork {
1919
LONDON,
20+
PARIS,
2021
SHANGHAI,
2122
CANCUN,
2223
PRAGUE;
2324

2425
public static String toString(Fork fork) {
2526
return switch (fork) {
2627
case LONDON -> "london";
28+
case PARIS -> "paris";
2729
case SHANGHAI -> "shanghai";
2830
case CANCUN -> "cancun";
2931
case PRAGUE -> "prague";
3032
};
3133
}
3234

35+
/**
36+
* Construct a fork instance from the name of a fork (e.g. "London", "Shanghai", etc). Observe
37+
* that case does not matter here. Hence, "LONDON", "London", "london", "lonDon" are all suitable
38+
* aliases for the LONDON instance.
39+
*
40+
* @param fork
41+
* @return
42+
*/
43+
public static Fork fromString(String fork) {
44+
return Fork.valueOf(fork.toUpperCase());
45+
}
46+
3347
public static boolean isPostShanghai(Fork fork) {
3448
return switch (fork) {
35-
case LONDON -> false;
49+
case LONDON, PARIS -> false;
3650
case SHANGHAI, CANCUN, PRAGUE -> true;
3751
};
3852
}

arithmetization/src/main/java/net/consensys/linea/zktracer/ZkTracer.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.util.Optional;
2828
import java.util.Set;
2929

30-
import com.fasterxml.jackson.databind.ObjectMapper;
31-
import com.fasterxml.jackson.databind.ObjectWriter;
3230
import lombok.Getter;
3331
import lombok.extern.slf4j.Slf4j;
3432
import net.consensys.linea.plugins.config.LineaL1L2BridgeSharedConfiguration;
@@ -53,14 +51,17 @@
5351
@Slf4j
5452
public class ZkTracer implements ConflationAwareOperationTracer {
5553

54+
/** Construct trace object. */
55+
private final Trace trace;
56+
5657
@Getter private final Hub hub;
5758
private final Optional<DebugMode> debugMode;
5859

5960
/** Accumulate all the exceptions that happened at tracing time. */
6061
@Getter private final List<Exception> tracingExceptions = new FiniteList<>(50);
6162

6263
// Fields for metadata
63-
private final ChainConfig chain;
64+
@Getter private final ChainConfig chain;
6465

6566
/**
6667
* Construct a ZkTracer for a given bridge configuration and chainId. This is used, for example,
@@ -88,41 +89,46 @@ public ZkTracer(ChainConfig chain) {
8889
this.hub =
8990
switch (chain.fork) {
9091
case LONDON -> new LondonHub(chain);
92+
case PARIS -> new ParisHub(chain);
9193
case SHANGHAI -> new ShanghaiHub(chain);
9294
case CANCUN -> new CancunHub(chain);
9395
case PRAGUE -> new PragueHub(chain);
9496
};
97+
this.trace =
98+
switch (chain.fork) {
99+
default -> new TraceLondon();
100+
// case SHANGHAI -> new TraceShanghai();
101+
};
95102
final DebugMode.PinLevel debugLevel = new DebugMode.PinLevel();
96103
this.debugMode =
97104
debugLevel.none() ? Optional.empty() : Optional.of(new DebugMode(debugLevel, this.hub));
98105
}
99106

100107
public void writeToFile(final Path filename, long startBlock, long endBlock) {
101108
maybeThrowTracingExceptions();
102-
103109
final List<Module> modulesToTrace = hub.getModulesToTrace();
104110
final List<Trace.ColumnHeader> headers =
105-
modulesToTrace.stream().flatMap(m -> m.columnHeaders().stream()).toList();
111+
modulesToTrace.stream().flatMap(m -> m.columnHeaders(trace).stream()).toList();
106112
// Configure metadata
107-
final Map<String, Object> metadata = Trace.metadata();
108-
metadata.put("releaseVersion", ZkTracer.class.getPackage().getSpecificationVersion());
109-
metadata.put("chainId", this.chain.id.toString());
110-
metadata.put("l2L1LogSmcAddress", this.chain.bridgeConfiguration.contract().toString());
111-
metadata.put("l2L1LogTopic", this.chain.bridgeConfiguration.topic().toString());
113+
trace.addMetadata("releaseVersion", ZkTracer.class.getPackage().getSpecificationVersion());
114+
trace.addMetadata("chainId", this.chain.id.toString());
115+
trace.addMetadata("l2L1LogSmcAddress", this.chain.bridgeConfiguration.contract().toString());
116+
trace.addMetadata("l2L1LogTopic", this.chain.bridgeConfiguration.topic().toString());
112117
// include block range
113118
final Map<String, String> range = new HashMap<>();
114119
range.put("start", Long.toString(startBlock));
115120
range.put("end", Long.toString(endBlock));
116-
metadata.put("conflation", range);
121+
trace.addMetadata("conflation", range);
117122
// include line counts
118123
final Map<String, String> lineCounts = new HashMap<>();
119124
for (Module m : hub.getTracelessModules()) {
120125
lineCounts.put(m.moduleKey(), Integer.toString(m.lineCount()));
121126
}
122-
metadata.put("lineCounts", lineCounts);
127+
trace.addMetadata("lineCounts", lineCounts);
123128
//
124129
try (RandomAccessFile file = new RandomAccessFile(filename.toString(), "rw")) {
125-
final Trace trace = Trace.of(file, headers, getMetadataBytes(metadata));
130+
// Open trace for writing
131+
trace.open(file, headers);
126132
// Commit each module
127133
for (Module m : modulesToTrace) {
128134
m.commit(trace);
@@ -317,19 +323,12 @@ public Map<String, Integer> getModulesLineCount() {
317323
final HashMap<String, Integer> modulesLineCount = new HashMap<>();
318324

319325
for (Module m : hub.getModulesToCount()) {
320-
modulesLineCount.put(m.moduleKey(), m.lineCount() + m.spillage());
326+
modulesLineCount.put(m.moduleKey(), m.lineCount() + m.spillage(this.trace));
321327
}
322328
//
323329
return modulesLineCount;
324330
}
325331

326-
/** Object writer is used for generating JSON byte strings. */
327-
private static final ObjectWriter objectWriter = new ObjectMapper().writer();
328-
329-
public static byte[] getMetadataBytes(Map<String, Object> metadata) throws IOException {
330-
return objectWriter.writeValueAsBytes(metadata);
331-
}
332-
333332
public Set<Address> getAddressesSeenByHubForRelativeBlock(final int relativeBlockNumber) {
334333
return hub.blockStack().getBlockByRelativeBlockNumber(relativeBlockNumber).addressesSeenByHub();
335334
}

arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/CountingOnlyModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ default int lineCount() {
4141
}
4242

4343
@Override
44-
default int spillage() {
44+
default int spillage(Trace trace) {
4545
return 0;
4646
}
4747

@@ -51,7 +51,7 @@ default void updateTally(final int count) {
5151
}
5252

5353
@Override
54-
default List<Trace.ColumnHeader> columnHeaders() {
54+
default List<Trace.ColumnHeader> columnHeaders(Trace trace) {
5555
throw new IllegalStateException("should never be called");
5656
}
5757

arithmetization/src/main/java/net/consensys/linea/zktracer/container/module/Module.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ default void tracePreOpcode(MessageFrame frame, OpCode opcode) {}
8080
*
8181
* @return
8282
*/
83-
int spillage();
83+
int spillage(Trace trace);
8484

85-
List<Trace.ColumnHeader> columnHeaders();
85+
List<Trace.ColumnHeader> columnHeaders(Trace trace);
8686

8787
default void commit(Trace trace) {
8888
throw new UnsupportedOperationException();

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ public void tracePreOpcode(MessageFrame frame, OpCode opcode) {
5858
}
5959

6060
@Override
61-
public List<Trace.ColumnHeader> columnHeaders() {
62-
return Trace.Add.headers(this.lineCount());
61+
public List<Trace.ColumnHeader> columnHeaders(Trace trace) {
62+
return trace.add().headers(this.lineCount());
6363
}
6464

6565
@Override
66-
public int spillage() {
67-
return Trace.Add.SPILLAGE;
66+
public int spillage(Trace trace) {
67+
return trace.add().spillage();
6868
}
6969

7070
@Override
7171
public void commit(Trace trace) {
7272
int stamp = 0;
7373
for (AddOperation op : sortOperations(new AddOperationComparator())) {
74-
op.trace(++stamp, trace.add);
74+
op.trace(++stamp, trace.add());
7575
}
7676
}
7777

arithmetization/src/main/java/net/consensys/linea/zktracer/module/bin/Bin.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ public void tracePreOpcode(MessageFrame frame, OpCode opcode) {
6464
}
6565

6666
@Override
67-
public List<Trace.ColumnHeader> columnHeaders() {
68-
return Trace.Bin.headers(this.lineCount());
67+
public List<Trace.ColumnHeader> columnHeaders(Trace trace) {
68+
return trace.bin().headers(this.lineCount());
6969
}
7070

7171
@Override
72-
public int spillage() {
73-
return Trace.Bin.SPILLAGE;
72+
public int spillage(Trace trace) {
73+
return trace.bin().spillage();
7474
}
7575

7676
@Override
7777
public void commit(Trace trace) {
7878
int stamp = 0;
7979
for (BinOperation op : operations.sortOperations(new BinOperationComparator())) {
80-
op.traceBinOperation(++stamp, trace.bin);
80+
op.traceBinOperation(++stamp, trace.bin());
8181
}
8282
}
8383
}

arithmetization/src/main/java/net/consensys/linea/zktracer/module/blake2fmodexpdata/BlakeModexpData.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ private void callWcpForIdCheck(final int operationID) {
6767
}
6868

6969
@Override
70-
public List<Trace.ColumnHeader> columnHeaders() {
71-
return Trace.Blake2fmodexpdata.headers(this.lineCount());
70+
public List<Trace.ColumnHeader> columnHeaders(Trace trace) {
71+
return trace.blake2fmodexpdata().headers(this.lineCount());
7272
}
7373

7474
@Override
75-
public int spillage() {
76-
return Trace.Blake2fmodexpdata.SPILLAGE;
75+
public int spillage(Trace trace) {
76+
return trace.blake2fmodexpdata().spillage();
7777
}
7878

7979
@Override
8080
public void commit(Trace trace) {
8181
int stamp = 0;
8282
for (BlakeModexpDataOperation o : operations.getAll()) {
83-
o.trace(trace.blake2fmodexpdata, ++stamp);
83+
o.trace(trace.blake2fmodexpdata(), ++stamp);
8484
}
8585
}
8686
}

0 commit comments

Comments
 (0)