Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved issues related to column type changes #1417

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void traceModexpResult(Trace trace, final UnsignedByte stamp) {

private void commonTrace(Trace trace, UnsignedByte stamp, int index, Bytes input, int indexMax) {
trace
.stamp(stamp)
.stamp(stamp.toInteger())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is the right way to do this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at UnsignedByte.java it seems ok to me. It's used to convert to BigInt to

.id(id)
.index(UnsignedByte.of(index))
.indexMax(UnsignedByte.of(indexMax))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Trace {

static List<ColumnHeader> headers(int length) {
return List.of(
new ColumnHeader("blake2fmodexpdata.ID", 6, length),
new ColumnHeader("blake2fmodexpdata.ID", 4, length),
new ColumnHeader("blake2fmodexpdata.INDEX", 1, length),
new ColumnHeader("blake2fmodexpdata.INDEX_MAX", 1, length),
new ColumnHeader("blake2fmodexpdata.IS_BLAKE_DATA", 1, length),
Expand All @@ -70,7 +70,7 @@ static List<ColumnHeader> headers(int length) {
new ColumnHeader("blake2fmodexpdata.IS_MODEXP_RESULT", 1, length),
new ColumnHeader("blake2fmodexpdata.LIMB", 16, length),
new ColumnHeader("blake2fmodexpdata.PHASE", 1, length),
new ColumnHeader("blake2fmodexpdata.STAMP", 1, length));
new ColumnHeader("blake2fmodexpdata.STAMP", 2, length));
}

public Trace(List<MappedByteBuffer> buffers) {
Expand Down Expand Up @@ -104,11 +104,9 @@ public Trace id(final long b) {
filled.set(0);
}

if (b >= 281474976710656L) {
if (b >= 4294967296L) {
throw new IllegalArgumentException("id has invalid value (" + b + ")");
}
id.put((byte) (b >> 40));
id.put((byte) (b >> 32));
id.put((byte) (b >> 24));
id.put((byte) (b >> 16));
id.put((byte) (b >> 8));
Expand Down Expand Up @@ -262,14 +260,18 @@ public Trace phase(final UnsignedByte b) {
return this;
}

public Trace stamp(final UnsignedByte b) {
public Trace stamp(final long b) {
if (filled.get(12)) {
throw new IllegalStateException("blake2fmodexpdata.STAMP already set");
} else {
filled.set(12);
}

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

return this;
}
Expand Down Expand Up @@ -335,7 +337,7 @@ public Trace validateRow() {

public Trace fillAndValidateRow() {
if (!filled.get(0)) {
id.position(id.position() + 6);
id.position(id.position() + 4);
}

if (!filled.get(1)) {
Expand Down Expand Up @@ -383,7 +385,7 @@ public Trace fillAndValidateRow() {
}

if (!filled.get(12)) {
stamp.position(stamp.position() + 1);
stamp.position(stamp.position() + 2);
}

filled.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,9 @@ void trace(Trace trace, final int stamp, final long previousId) {
.id(id)
.index(isData ? i : i - nRowsData)
.limb(limb.get(i))
.totalSize(Bytes.ofUnsignedLong(getTotalSize(precompileFlag, isData)))
.totalSize(getTotalSize(precompileFlag, isData))
.phase(getPhase(precompileFlag, isData))
.indexMax(Bytes.ofUnsignedLong(getIndexMax(precompileFlag, isData)))
.indexMax(getIndexMax(precompileFlag, isData))
.successBit(successBit)
.isEcrecoverData(precompileFlag == PRC_ECRECOVER && isData)
.isEcrecoverResult(precompileFlag == PRC_ECRECOVER && !isData)
Expand All @@ -689,11 +689,11 @@ void trace(Trace trace, final int stamp, final long previousId) {
.isEcmulResult(precompileFlag == PRC_ECMUL && !isData)
.isEcpairingData(precompileFlag == PRC_ECPAIRING && isData)
.isEcpairingResult(precompileFlag == PRC_ECPAIRING && !isData)
.totalPairings(Bytes.ofUnsignedLong(totalPairings))
.totalPairings(totalPairings)
.accPairings(
precompileFlag == PRC_ECPAIRING && isData
? Bytes.ofUnsignedLong(1 + i / (INDEX_MAX_ECPAIRING_DATA_MIN + 1))
: Bytes.of(0))
? 1 + i / (INDEX_MAX_ECPAIRING_DATA_MIN + 1)
: 0)
.internalChecksPassed(internalChecksPassed)
.hurdle(hurdle.get(i))
.byteDelta(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class Trace {

static List<ColumnHeader> headers(int length) {
return List.of(
new ColumnHeader("ecdata.ACC_PAIRINGS", 32, length),
new ColumnHeader("ecdata.ACC_PAIRINGS", 2, length),
new ColumnHeader("ecdata.ACCEPTABLE_PAIR_OF_POINTS_FOR_PAIRING_CIRCUIT", 1, length),
new ColumnHeader("ecdata.BYTE_DELTA", 1, length),
new ColumnHeader("ecdata.CIRCUIT_SELECTOR_ECADD", 1, length),
Expand All @@ -147,7 +147,7 @@ static List<ColumnHeader> headers(int length) {
new ColumnHeader("ecdata.HURDLE", 1, length),
new ColumnHeader("ecdata.ID", 4, length),
new ColumnHeader("ecdata.INDEX", 2, length),
new ColumnHeader("ecdata.INDEX_MAX", 32, length),
new ColumnHeader("ecdata.INDEX_MAX", 2, length),
new ColumnHeader("ecdata.INTERNAL_CHECKS_PASSED", 1, length),
new ColumnHeader("ecdata.IS_ECADD_DATA", 1, length),
new ColumnHeader("ecdata.IS_ECADD_RESULT", 1, length),
Expand All @@ -168,8 +168,8 @@ static List<ColumnHeader> headers(int length) {
new ColumnHeader("ecdata.PHASE", 2, length),
new ColumnHeader("ecdata.STAMP", 4, length),
new ColumnHeader("ecdata.SUCCESS_BIT", 1, length),
new ColumnHeader("ecdata.TOTAL_PAIRINGS", 32, length),
new ColumnHeader("ecdata.TOTAL_SIZE", 32, length),
new ColumnHeader("ecdata.TOTAL_PAIRINGS", 2, length),
new ColumnHeader("ecdata.TOTAL_SIZE", 2, length),
new ColumnHeader("ecdata.WCP_ARG1_HI", 16, length),
new ColumnHeader("ecdata.WCP_ARG1_LO", 16, length),
new ColumnHeader("ecdata.WCP_ARG2_HI", 16, length),
Expand Down Expand Up @@ -244,28 +244,18 @@ public int size() {
return this.currentLine;
}

public Trace accPairings(final Bytes b) {
public Trace accPairings(final long b) {
if (filled.get(1)) {
throw new IllegalStateException("ecdata.ACC_PAIRINGS already set");
} else {
filled.set(1);
}

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

return this;
}
Expand Down Expand Up @@ -673,27 +663,18 @@ public Trace index(final long b) {
return this;
}

public Trace indexMax(final Bytes b) {
public Trace indexMax(final long b) {
if (filled.get(24)) {
throw new IllegalStateException("ecdata.INDEX_MAX already set");
} else {
filled.set(24);
}

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

return this;
}
Expand Down Expand Up @@ -961,54 +942,34 @@ public Trace successBit(final Boolean b) {
return this;
}

public Trace totalPairings(final Bytes b) {
public Trace totalPairings(final long b) {
if (filled.get(45)) {
throw new IllegalStateException("ecdata.TOTAL_PAIRINGS already set");
} else {
filled.set(45);
}

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

return this;
}

public Trace totalSize(final Bytes b) {
public Trace totalSize(final long b) {
if (filled.get(46)) {
throw new IllegalStateException("ecdata.TOTAL_SIZE already set");
} else {
filled.set(46);
}

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

return this;
}
Expand Down Expand Up @@ -1379,7 +1340,7 @@ public Trace validateRow() {

public Trace fillAndValidateRow() {
if (!filled.get(1)) {
accPairings.position(accPairings.position() + 32);
accPairings.position(accPairings.position() + 2);
}

if (!filled.get(0)) {
Expand Down Expand Up @@ -1476,7 +1437,7 @@ public Trace fillAndValidateRow() {
}

if (!filled.get(24)) {
indexMax.position(indexMax.position() + 32);
indexMax.position(indexMax.position() + 2);
}

if (!filled.get(25)) {
Expand Down Expand Up @@ -1560,11 +1521,11 @@ public Trace fillAndValidateRow() {
}

if (!filled.get(45)) {
totalPairings.position(totalPairings.position() + 32);
totalPairings.position(totalPairings.position() + 2);
}

if (!filled.get(46)) {
totalSize.position(totalSize.position() + 32);
totalSize.position(totalSize.position() + 2);
}

if (!filled.get(47)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import net.consensys.linea.zktracer.module.ext.calculator.AbstractExtCalculator;
import net.consensys.linea.zktracer.opcode.OpCode;
import net.consensys.linea.zktracer.types.UnsignedByte;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;

Expand Down Expand Up @@ -273,13 +272,13 @@ void trace(Trace trace, int stamp) {
.ofJ(this.overflowJ[i])
.ofI(this.overflowI[i])
.ofRes(this.overflowRes[i])
.ct(Bytes.of(i))
.inst(Bytes.of(this.opCode.byteValue()))
.ct(i)
.inst(UnsignedByte.of(this.opCode.byteValue()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use opCode.unsignedByteValue()

.oli(this.isOneLineInstruction)
.bit1(this.getBit1())
.bit2(this.getBit2())
.bit3(this.getBit3())
.stamp(Bytes.ofUnsignedLong(stamp))
.stamp(stamp)
.validateRow();
}
}
Expand Down
Loading
Loading