Skip to content

Commit

Permalink
Fixing issues with column sizes (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierBBB authored Oct 9, 2024
1 parent 34c09d3 commit 10837e9
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

/**
* Implements a system of pseudo-stacked squashed List where {@link
* operationsCommitedToTheConflation} represents the List of all operations since the beginning of
* the conflation and {@link operationsInTransaction} represents the operations added by the last
* ModuleOperationStackedList#operationsCommitedToTheConflation} represents the List of all
* operations since the beginning of the conflation and {@link
* ModuleOperationStackedList#operationsInTransaction} represents the operations added by the last
* transaction. We can pop only the operations added by last transaction. The line counting is done
* by a separate {@link CountOnlyOperation}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package net.consensys.linea.zktracer.module.blockdata;

import static net.consensys.linea.zktracer.module.blockdata.Trace.MAX_CT;
import static net.consensys.linea.zktracer.module.blockdata.Trace.CT_MAX_FOR_BLOCKDATA;

import java.math.BigInteger;
import java.nio.MappedByteBuffer;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void popTransaction() {}
@Override
public int lineCount() {
final int numberOfBlock = conflationFinished ? operations.size() : operations.size() + 1;
return numberOfBlock * (MAX_CT + 1);
return numberOfBlock * (CT_MAX_FOR_BLOCKDATA + 1);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package net.consensys.linea.zktracer.module.blockdata;

import static net.consensys.linea.zktracer.module.blockdata.Trace.MAX_CT;
import static net.consensys.linea.zktracer.module.blockdata.Trace.CT_MAX_FOR_BLOCKDATA;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_BASEFEE;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_CHAINID;
import static net.consensys.linea.zktracer.module.constants.GlobalConstants.EVM_INST_COINBASE;
Expand Down Expand Up @@ -51,12 +51,12 @@ public class BlockdataOperation extends ModuleOperation {

@Override
protected int computeLineCount() {
return MAX_CT + 1;
return CT_MAX_FOR_BLOCKDATA + 1;
}

public void trace(
Trace trace, final int relBlock, final long firstBlockNumber, final BigInteger chainId) {
for (short ct = 0; ct <= MAX_CT; ct++) {
for (short ct = 0; ct <= CT_MAX_FOR_BLOCKDATA; ct++) {
traceBlockConstant(trace, relBlock, firstBlockNumber);
traceRowDependant(trace, ct, relBlock, chainId);
trace.validateRow();
Expand Down Expand Up @@ -98,7 +98,7 @@ private void traceRowDependant(
trace.inst(UnsignedByte.of(EVM_INST_BASEFEE)).wcpFlag(false);
}
default -> throw new IllegalArgumentException(
String.format("Blockdata max CT is %s, can't write %s", MAX_CT, ct));
String.format("Blockdata max CT is %s, can't write %s", CT_MAX_FOR_BLOCKDATA, ct));
}

trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Please DO NOT ATTEMPT TO MODIFY this code directly.
*/
public class Trace {
public static final int MAX_CT = 0x6;
public static final int CT_MAX_FOR_BLOCKDATA = 0x6;
public static final int ROW_SHIFT_BASEFEE = 0x6;
public static final int ROW_SHIFT_CHAINID = 0x5;
public static final int ROW_SHIFT_COINBASE = 0x0;
Expand Down Expand Up @@ -130,8 +130,8 @@ static List<ColumnHeader> headers(int length) {
new ColumnHeader("blockdata.DATA_LO", 16, length),
new ColumnHeader("blockdata.FIRST_BLOCK_NUMBER", 6, length),
new ColumnHeader("blockdata.INST", 1, length),
new ColumnHeader("blockdata.REL_BLOCK", 1, length),
new ColumnHeader("blockdata.REL_TX_NUM_MAX", 1, length),
new ColumnHeader("blockdata.REL_BLOCK", 2, length),
new ColumnHeader("blockdata.REL_TX_NUM_MAX", 2, length),
new ColumnHeader("blockdata.WCP_FLAG", 1, length));
}

Expand Down Expand Up @@ -762,9 +762,10 @@ public Trace relBlock(final long b) {
filled.set(41);
}

if (b >= 256L) {
if (b >= 1024L) {
throw new IllegalArgumentException("relBlock has invalid value (" + b + ")");
}
relBlock.put((byte) (b >> 8));
relBlock.put((byte) b);

return this;
Expand All @@ -777,9 +778,10 @@ public Trace relTxNumMax(final long b) {
filled.set(42);
}

if (b >= 256L) {
if (b >= 1024L) {
throw new IllegalArgumentException("relTxNumMax has invalid value (" + b + ")");
}
relTxNumMax.put((byte) (b >> 8));
relTxNumMax.put((byte) b);

return this;
Expand Down Expand Up @@ -1146,11 +1148,11 @@ public Trace fillAndValidateRow() {
}

if (!filled.get(41)) {
relBlock.position(relBlock.position() + 1);
relBlock.position(relBlock.position() + 2);
}

if (!filled.get(42)) {
relTxNumMax.position(relTxNumMax.position() + 1);
relTxNumMax.position(relTxNumMax.position() + 2);
}

if (!filled.get(43)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ public void traceContextEnter(MessageFrame frame) {

final long callDataContextNumber = callStack.currentCallFrame().contextNumber();

currentFrame().rememberGasNextBeforePausing();
currentFrame().pauseCurrentFrame();

callStack.enter(
frameType,
newChildContextNumber(),
Expand Down Expand Up @@ -976,9 +979,15 @@ public long remainingGas() {
}

public long expectedGas() {
return this.state().getProcessingPhase() == TX_EXEC
? this.currentFrame().frame().getRemainingGas()
: 0;

if (this.state().getProcessingPhase() != TX_EXEC) return 0;

if (this.currentFrame().executionPaused()) {
currentFrame().unpauseCurrentFrame();
return currentFrame().lastValidGasNext();
}

return this.currentFrame().frame().getRemainingGas();
}

public int cumulatedTxCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,11 @@ static List<ColumnHeader> headers(int length) {
"hub.EXISTS_xor_MMU_SUCCESS_BIT_xor_CALL_EOA_SUCCESS_CALLER_WONT_REVERT_xor_BTC_FLAG_xor_VALUE_CURR_IS_ORIG_xor_REQUIRES_EVM_EXECUTION",
1,
length),
new ColumnHeader("hub.GAS_ACTUAL", 4, length),
new ColumnHeader("hub.GAS_ACTUAL", 8, length),
new ColumnHeader("hub.GAS_COST", 8, length),
new ColumnHeader("hub.GAS_EXPECTED", 4, length),
new ColumnHeader("hub.GAS_EXPECTED", 8, length),
new ColumnHeader("hub.GAS_LIMIT", 8, length),
new ColumnHeader("hub.GAS_NEXT", 4, length),
new ColumnHeader("hub.GAS_NEXT", 8, length),
new ColumnHeader("hub.GAS_PRICE", 8, length),
new ColumnHeader(
"hub.HAS_CODE_NEW_xor_MXP_MTNTOP_xor_CALL_PRC_SUCCESS_CALLER_WILL_REVERT_xor_COPY_FLAG_xor_VALUE_NEXT_IS_ORIG",
Expand Down Expand Up @@ -928,20 +928,28 @@ public Trace exceptionAhoy(final Boolean b) {
return this;
}

public Trace gasActual(final long b) {
public Trace gasActual(final Bytes b) {
if (filled.get(14)) {
throw new IllegalStateException("hub.GAS_ACTUAL already set");
} else {
filled.set(14);
}

if (b >= 4294967296L) {
throw new IllegalArgumentException("gasActual has invalid value (" + b + ")");
// Trim array to size
Bytes bs = b.trimLeadingZeros();
// Sanity check against expected width
if (bs.bitLength() > 64) {
throw new IllegalArgumentException(
"gasActual has invalid width (" + bs.bitLength() + "bits)");
}
// Write padding (if necessary)
for (int i = bs.size(); i < 8; i++) {
gasActual.put((byte) 0);
}
// Write bytes
for (int j = 0; j < bs.size(); j++) {
gasActual.put(bs.get(j));
}
gasActual.put((byte) (b >> 24));
gasActual.put((byte) (b >> 16));
gasActual.put((byte) (b >> 8));
gasActual.put((byte) b);

return this;
}
Expand Down Expand Up @@ -971,38 +979,53 @@ public Trace gasCost(final Bytes b) {
return this;
}

public Trace gasExpected(final long b) {
public Trace gasExpected(final Bytes b) {
if (filled.get(16)) {
throw new IllegalStateException("hub.GAS_EXPECTED already set");
} else {
filled.set(16);
}

if (b >= 4294967296L) {
throw new IllegalArgumentException("gasExpected has invalid value (" + b + ")");
// Trim array to size
Bytes bs = b.trimLeadingZeros();
// Sanity check against expected width
if (bs.bitLength() > 64) {
throw new IllegalArgumentException(
"gasExpected has invalid width (" + bs.bitLength() + "bits)");
}
// Write padding (if necessary)
for (int i = bs.size(); i < 8; i++) {
gasExpected.put((byte) 0);
}
// Write bytes
for (int j = 0; j < bs.size(); j++) {
gasExpected.put(bs.get(j));
}
gasExpected.put((byte) (b >> 24));
gasExpected.put((byte) (b >> 16));
gasExpected.put((byte) (b >> 8));
gasExpected.put((byte) b);

return this;
}

public Trace gasNext(final long b) {
public Trace gasNext(final Bytes b) {
if (filled.get(17)) {
throw new IllegalStateException("hub.GAS_NEXT already set");
} else {
filled.set(17);
}

if (b >= 4294967296L) {
throw new IllegalArgumentException("gasNext has invalid value (" + b + ")");
// Trim array to size
Bytes bs = b.trimLeadingZeros();
// Sanity check against expected width
if (bs.bitLength() > 64) {
throw new IllegalArgumentException("gasNext has invalid width (" + bs.bitLength() + "bits)");
}
// Write padding (if necessary)
for (int i = bs.size(); i < 8; i++) {
gasNext.put((byte) 0);
}
// Write bytes
for (int j = 0; j < bs.size(); j++) {
gasNext.put(bs.get(j));
}
gasNext.put((byte) (b >> 24));
gasNext.put((byte) (b >> 16));
gasNext.put((byte) (b >> 8));
gasNext.put((byte) b);

return this;
}
Expand Down Expand Up @@ -8191,23 +8214,23 @@ public Trace fillAndValidateRow() {
}

if (!filled.get(14)) {
gasActual.position(gasActual.position() + 4);
gasActual.position(gasActual.position() + 8);
}

if (!filled.get(15)) {
gasCost.position(gasCost.position() + 8);
}

if (!filled.get(16)) {
gasExpected.position(gasExpected.position() + 4);
gasExpected.position(gasExpected.position() + 8);
}

if (!filled.get(120)) {
gasLimit.position(gasLimit.position() + 8);
}

if (!filled.get(17)) {
gasNext.position(gasNext.position() + 4);
gasNext.position(gasNext.position() + 8);
}

if (!filled.get(121)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void setCodeFragmentIndex(Hub hub) {
}
}

public int getAccumulativeGasUsedInBlockBeforeTxStart() {
public long getAccumulativeGasUsedInBlockBeforeTxStart() {
return this.relativeTransactionNumber == 1 ? 0 : this.previous().getAccumulatedGasUsedInBlock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ public Trace trace(Trace trace) {
.height(commonFragmentValues.height)
.heightNew(commonFragmentValues.heightNew)
// peeking flags are traced in the respective fragments
.gasExpected(commonFragmentValues.gasExpected)
.gasActual(commonFragmentValues.gasActual)
.gasExpected(Bytes.ofUnsignedLong(commonFragmentValues.gasExpected))
.gasActual(Bytes.ofUnsignedLong(commonFragmentValues.gasActual))
.gasCost(Bytes.ofUnsignedLong(commonFragmentValues.gasCost))
.gasNext(commonFragmentValues.gasNext)
.gasNext(Bytes.ofUnsignedLong(commonFragmentValues.gasNext))
.refundCounter(commonFragmentValues.gasRefund)
.refundCounterNew(commonFragmentValues.gasRefundNew)
.twoLineInstruction(commonFragmentValues.TLI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public class RamToExoWithPadding implements MmuInstruction {
private long initialSourceLimbOffset;
private short initialSourceByteOffset;
private boolean hasRightPadding;
private int paddingSize;
private int extractionSize;
private long paddingSize;
private long extractionSize;

public RamToExoWithPadding(Euc euc, Wcp wcp) {
this.euc = euc;
Expand Down Expand Up @@ -128,7 +128,7 @@ private void row2(final MmuData mmuData) {
paddingSize = hasRightPadding ? (int) (refSize - size) : 0;
extractionSize = (int) (hasRightPadding ? size : refSize);

final Bytes dividend = Bytes.ofUnsignedShort(paddingSize);
final Bytes dividend = Bytes.ofUnsignedLong(paddingSize);
final EucOperation eucOp = euc.callEUC(dividend, Bytes.of(LLARGE));

eucCallRecords.add(
Expand All @@ -144,7 +144,7 @@ private void row2(final MmuData mmuData) {

private void row3(final MmuData mmuData) {
// row n°3
final Bytes dividend = Bytes.ofUnsignedShort(extractionSize);
final Bytes dividend = Bytes.ofUnsignedLong(extractionSize);
final EucOperation eucOp = euc.callEUC(dividend, Bytes.of(LLARGE));

Bytes quotient = eucOp.quotient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public class MmuWcpCallRecord {
@Builder.Default private Bytes arg2Lo = Bytes.EMPTY;
private boolean result;

public static MmuWcpCallRecord.MmuWcpCallRecordBuilder instLtBuilder() {
public static MmuWcpCallRecordBuilder instLtBuilder() {
return builder().instruction(UnsignedByte.of(GlobalConstants.EVM_INST_LT));
}

public static MmuWcpCallRecord.MmuWcpCallRecordBuilder instEqBuilder() {
public static MmuWcpCallRecordBuilder instEqBuilder() {
return builder().instruction(UnsignedByte.of(GlobalConstants.EVM_INST_EQ));
}

public static MmuWcpCallRecord.MmuWcpCallRecordBuilder instIsZeroBuilder() {
public static MmuWcpCallRecordBuilder instIsZeroBuilder() {
return builder().instruction(OpCode.ISZERO.unsignedByteValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void traceOperation(
phase2(traceValue, chunk.status(), trace);

// PHASE 3: Cumulative gas Ru.
phase3(traceValue, (long) chunk.gasUsed(), trace);
phase3(traceValue, chunk.gasUsed(), trace);

// PHASE 4: Bloom Filter Rb.
phase4(traceValue, chunk.logs(), trace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public final class RlpTxrcptOperation extends ModuleOperation {
private final TransactionType txType;
private final Boolean status;
private final int gasUsed;
private final long gasUsed;
private final List<Log> logs;

@Override
Expand Down
Loading

0 comments on commit 10837e9

Please sign in to comment.