diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackOnlySection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackOnlySection.java index 07ceedaa87..d6f5aee27a 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackOnlySection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/StackOnlySection.java @@ -19,7 +19,7 @@ public class StackOnlySection extends TraceSection { public StackOnlySection(Hub hub) { - super(hub, (short) (hub.opCode().getData().stackSettings().twoLineInstruction() ? 2 : 1)); + super(hub, (short) (hub.opCode().getData().numberOfStackRows())); this.addStack(hub); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TraceSection.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TraceSection.java index ee180b48c6..5d39d66563 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TraceSection.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/hub/section/TraceSection.java @@ -161,7 +161,7 @@ private List makeStackFragments(final Hub hub, CallFrame f) { final List r = new ArrayList<>(2); Stack snapshot = f.stack().snapshot(); if (f.pending().lines().isEmpty()) { - for (int i = 0; i < (f.opCodeData().stackSettings().twoLineInstruction() ? 2 : 1); i++) { + for (int i = 0; i < (f.opCodeData().numberOfStackRows()); i++) { r.add( StackFragment.prepare( hub, diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCode.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCode.java index c1a5f34ac8..0c247a3c52 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCode.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCode.java @@ -259,7 +259,7 @@ public boolean isAnyOf(OpCode... opCodes) { } public short numberOfStackRows() { - return (short) (this.getData().stackSettings().twoLineInstruction() ? 2 : 1); + return (short) (this.getData().numberOfStackRows()); } public boolean mayTriggerStackUnderflow() { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java index f098c1baa1..a845f42783 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/opcode/OpCodeData.java @@ -109,4 +109,8 @@ public boolean isInvalid() { public boolean isMxp() { return this.billing().type() != MxpType.NONE; } + + public int numberOfStackRows() { + return stackSettings.twoLineInstruction() ? 2 : 1; + } } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java index c587df290d..0a59f7a165 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/runtime/stack/Stack.java @@ -375,13 +375,13 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp currentOpcodeData = hub.opCodeData(); callFrame.pending(new StackContext(currentOpcodeData.mnemonic())); - final int alpha = currentOpcodeData.stackSettings().alpha(); - final int delta = currentOpcodeData.stackSettings().delta(); + final short delta = (short) currentOpcodeData.stackSettings().delta(); + final short alpha = (short) currentOpcodeData.stackSettings().alpha(); Preconditions.checkArgument(heightNew == frame.stackSize()); height = (short) frame.stackSize(); - heightNew += currentOpcodeData.stackSettings().nbAdded(); - heightNew -= currentOpcodeData.stackSettings().nbRemoved(); + heightNew -= delta; + heightNew += alpha; if (frame.stackSize() < delta) { // Testing for underflow status = Status.UNDERFLOW; @@ -411,12 +411,8 @@ public void processInstruction(final Hub hub, MessageFrame frame, int stackStamp if (status.isFailure()) { heightNew = 0; - - if (currentOpcodeData.stackSettings().twoLineInstruction()) { - stamp += callFrame.pending().addEmptyLines(2); - } else { - stamp += callFrame.pending().addEmptyLines(1); - } + final int numberOfStackRows = currentOpcodeData.numberOfStackRows(); + callFrame.pending().addEmptyLines(numberOfStackRows); return; }