Skip to content

Commit 51c8f33

Browse files
make inst decoder fork dependant
Signed-off-by: F Bojarski <[email protected]>
1 parent 60e9b60 commit 51c8f33

File tree

7 files changed

+103
-11
lines changed

7 files changed

+103
-11
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public Hub(final ChainConfig chain) {
379379
mmu = new Mmu(euc, wcp);
380380
mmio = new Mmio(mmu);
381381

382-
refTableModules = List.of(new BinRt(), new InstructionDecoder(), new ShfRt());
382+
refTableModules = List.of(new BinRt(), setInstructionDecoder(), new ShfRt());
383383

384384
modules =
385385
Stream.concat(
@@ -1073,4 +1073,8 @@ protected TransactionStack setTransactionStack() {
10731073
protected TxnData setTxnData() {
10741074
return null;
10751075
}
1076+
1077+
protected InstructionDecoder setInstructionDecoder() {
1078+
throw new IllegalStateException("must be implemented");
1079+
}
10761080
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import net.consensys.linea.zktracer.ChainConfig;
1919
import net.consensys.linea.zktracer.module.hub.state.LondonTransactionStack;
2020
import net.consensys.linea.zktracer.module.hub.state.TransactionStack;
21+
import net.consensys.linea.zktracer.module.tables.instructionDecoder.InstructionDecoder;
22+
import net.consensys.linea.zktracer.module.tables.instructionDecoder.LondonInstructionDecoder;
2123
import net.consensys.linea.zktracer.module.txndata.module.LondonTxnData;
2224
import net.consensys.linea.zktracer.module.txndata.module.TxnData;
2325

@@ -35,4 +37,9 @@ protected TransactionStack setTransactionStack() {
3537
protected TxnData setTxnData() {
3638
return new LondonTxnData(this, wcp(), euc());
3739
}
40+
41+
@Override
42+
protected InstructionDecoder setInstructionDecoder() {
43+
return new LondonInstructionDecoder();
44+
}
3845
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import net.consensys.linea.zktracer.ChainConfig;
1919
import net.consensys.linea.zktracer.module.hub.state.ShanghaiTransactionStack;
2020
import net.consensys.linea.zktracer.module.hub.state.TransactionStack;
21+
import net.consensys.linea.zktracer.module.tables.instructionDecoder.InstructionDecoder;
22+
import net.consensys.linea.zktracer.module.tables.instructionDecoder.ShanghaiInstructionDecoder;
2123
import net.consensys.linea.zktracer.module.txndata.module.ShanghaiTxnData;
2224
import net.consensys.linea.zktracer.module.txndata.module.TxnData;
2325

@@ -35,4 +37,9 @@ protected TransactionStack setTransactionStack() {
3537
protected TxnData setTxnData() {
3638
return new ShanghaiTxnData(this, wcp(), euc());
3739
}
40+
41+
@Override
42+
protected InstructionDecoder setInstructionDecoder() {
43+
return new ShanghaiInstructionDecoder();
44+
}
3845
}

arithmetization/src/main/java/net/consensys/linea/zktracer/module/tables/instructionDecoder/InstructionDecoder.java

+26-10
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import net.consensys.linea.zktracer.opcode.gas.MxpType;
2727
import net.consensys.linea.zktracer.types.UnsignedByte;
2828

29-
public final class InstructionDecoder implements Module {
29+
public abstract class InstructionDecoder implements Module {
3030
private static void traceFamily(OpCodeData op, Trace.Instdecoder trace) {
3131
trace
3232
.familyAdd(op.instructionFamily() == InstructionFamily.ADD)
@@ -120,15 +120,31 @@ public void commit(Trace trace) {
120120
for (int i = 0; i < 256; i++) {
121121
final OpCodeData op = OpCode.of(i).getData();
122122

123-
traceFamily(op, trace.instdecoder);
124-
traceStackSettings(op, trace.instdecoder);
125-
traceBillingSettings(op, trace.instdecoder);
126-
trace
127-
.instdecoder
128-
.opcode(UnsignedByte.of(i))
129-
.isPush(op.isPushNotZero())
130-
.isJumpdest(op.isJumpDest())
131-
.validateRow();
123+
if (op.isPushZero()) {
124+
tracePushZero(trace);
125+
continue;
126+
}
127+
traceOpcode(op, trace);
132128
}
133129
}
130+
131+
protected void traceOpcode(final OpCodeData op, final Trace trace) {
132+
traceFamily(op, trace.instdecoder);
133+
traceStackSettings(op, trace.instdecoder);
134+
traceBillingSettings(op, trace.instdecoder);
135+
trace
136+
.instdecoder
137+
.opcode(UnsignedByte.of(op.value()))
138+
.isPush(op.isPushNotZero())
139+
.isJumpdest(op.isJumpDest())
140+
.validateRow();
141+
}
142+
143+
protected void tracePushZero(Trace trace) {
144+
throw new IllegalStateException("must be implemented");
145+
}
146+
147+
protected void traceAsInvalid(final int opcode, final Trace trace) {
148+
trace.instdecoder.familyInvalid(true).opcode(UnsignedByte.of(opcode)).fillAndValidateRow();
149+
}
134150
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright ConsenSys Inc.
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.tables.instructionDecoder;
17+
18+
import static net.consensys.linea.zktracer.Trace.EVM_INST_PUSH0;
19+
20+
import net.consensys.linea.zktracer.Trace;
21+
22+
public class LondonInstructionDecoder extends InstructionDecoder {
23+
@Override
24+
protected void tracePushZero(Trace trace) {
25+
traceAsInvalid(EVM_INST_PUSH0, trace);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright ConsenSys Inc.
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.tables.instructionDecoder;
17+
18+
import static net.consensys.linea.zktracer.opcode.OpCode.PUSH0;
19+
20+
import net.consensys.linea.zktracer.Trace;
21+
22+
public class ShanghaiInstructionDecoder extends LondonInstructionDecoder {
23+
@Override
24+
protected void tracePushZero(Trace trace) {
25+
traceOpcode(PUSH0.getData(), trace);
26+
}
27+
}

arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ public boolean isPushNotZero() {
7878
return (EVM_INST_PUSH1 <= value) && (value <= EVM_INST_PUSH32);
7979
}
8080

81+
public boolean isPushZero() {
82+
return EVM_INST_PUSH0 == value;
83+
}
84+
8185
public boolean isJumpDest() {
8286
return value == EVM_INST_JUMPDEST;
8387
}

0 commit comments

Comments
 (0)