Skip to content

Commit e14e5e3

Browse files
authored
HUB -> ROM lookup fix (#1640)
1 parent c0c9f46 commit e14e5e3

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

tracer/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/fragment/StackFragment.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public final class StackFragment implements TraceFragment {
5656
private EWord hashInfoKeccak = EWord.ZERO;
5757
@Setter public Bytes hash;
5858
@Getter private final OpCode opCode;
59+
@Getter private final int rawOpCode;
5960
@Setter private boolean jumpDestinationVettingRequired;
6061
@Setter private boolean validJumpDestination;
6162
private final State.TxState.Stamps stamps;
@@ -74,6 +75,13 @@ private StackFragment(
7475
this.stackOps = stackOps;
7576
this.exceptions = exceptions;
7677
this.opCode = stack.getCurrentOpcodeData().mnemonic();
78+
if (this.opCode != OpCode.INVALID) {
79+
this.rawOpCode = 0xff & this.opCode.byteValue();
80+
} else {
81+
final int codeSize = hub.messageFrame().getCode().getBytes().size();
82+
final int pc = hub.messageFrame().getPC();
83+
this.rawOpCode = (pc < codeSize) ? 0xff & hub.messageFrame().getCode().getBytes().get(pc) : 0;
84+
}
7785
this.hashInfoFlag =
7886
switch (this.opCode) {
7987
case SHA3 -> true;
@@ -212,7 +220,7 @@ public Trace trace(Trace trace) {
212220
// Instruction details
213221
.pStackAlpha(UnsignedByte.of(stack.getCurrentOpcodeData().stackSettings().alpha()))
214222
.pStackDelta(UnsignedByte.of(stack.getCurrentOpcodeData().stackSettings().delta()))
215-
.pStackInstruction(Bytes.of(stack.getCurrentOpcodeData().value()))
223+
.pStackInstruction(Bytes.of(rawOpCode))
216224
.pStackStaticGas(staticGas)
217225
// Opcode families
218226
.pStackAccFlag(currentInstFamily == ACCOUNT)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import java.util.Objects;
2121

2222
import net.consensys.linea.zktracer.opcode.gas.Billing;
23+
import net.consensys.linea.zktracer.opcode.gas.BillingRate;
24+
import net.consensys.linea.zktracer.opcode.gas.GasConstants;
2325
import net.consensys.linea.zktracer.opcode.gas.MxpType;
26+
import net.consensys.linea.zktracer.opcode.stack.Pattern;
2427
import net.consensys.linea.zktracer.opcode.stack.StackSettings;
2528

2629
/**
@@ -46,6 +49,28 @@ public Billing billing() {
4649
return Objects.requireNonNullElse(billing, Billing.DEFAULT);
4750
}
4851

52+
public static OpCodeData forNonOpCodes(int value) {
53+
return new OpCodeData(
54+
OpCode.INVALID,
55+
value,
56+
INVALID,
57+
new StackSettings(
58+
Pattern.ZERO_ZERO,
59+
0,
60+
0,
61+
GasConstants.G_ZERO,
62+
false,
63+
false,
64+
false,
65+
false,
66+
false,
67+
false,
68+
false,
69+
false),
70+
new RamSettings(DataLocation.NONE, DataLocation.NONE),
71+
new Billing(GasConstants.G_ZERO, BillingRate.NONE, MxpType.NONE));
72+
}
73+
4974
/**
5075
* A method singling out <code>PUSHx</code> instructions.
5176
*

tracer/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static OpCodeData of(final int value) {
7070
throw new IllegalArgumentException("No OpCode with value %s is defined.".formatted(value));
7171
}
7272

73-
return valueToOpCodeDataMap.getOrDefault(value, of(OpCode.INVALID));
73+
return valueToOpCodeDataMap.getOrDefault(value, OpCodeData.forNonOpCodes(value));
7474
}
7575

7676
/**

0 commit comments

Comments
 (0)