|
26 | 26 | import net.consensys.linea.zktracer.opcode.gas.MxpType;
|
27 | 27 | import net.consensys.linea.zktracer.types.UnsignedByte;
|
28 | 28 |
|
29 |
| -public final class InstructionDecoder implements Module { |
| 29 | +public abstract class InstructionDecoder implements Module { |
30 | 30 | private static void traceFamily(OpCodeData op, Trace.Instdecoder trace) {
|
31 | 31 | trace
|
32 | 32 | .familyAdd(op.instructionFamily() == InstructionFamily.ADD)
|
@@ -120,15 +120,31 @@ public void commit(Trace trace) {
|
120 | 120 | for (int i = 0; i < 256; i++) {
|
121 | 121 | final OpCodeData op = OpCode.of(i).getData();
|
122 | 122 |
|
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); |
132 | 128 | }
|
133 | 129 | }
|
| 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 | + } |
134 | 150 | }
|
0 commit comments