From f916b0650e65d95071da0f9496285c3d782fcac7 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 3 Feb 2024 22:28:20 +0100 Subject: [PATCH 1/5] feat(txnData): add check callData is zero --- .../linea/zktracer/module/txn_data/Trace.java | 99 ++++++++++++------- .../module/txn_data/TransactionSnapshot.java | 4 + .../zktracer/module/txn_data/TxnData.java | 42 ++++---- zkevm-constraints | 2 +- 4 files changed, 88 insertions(+), 59 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java index 1700e61bfd..76d5e27e72 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java @@ -88,6 +88,7 @@ public class Trace { private final MappedByteBuffer statusCode; private final MappedByteBuffer toHi; private final MappedByteBuffer toLo; + private final MappedByteBuffer txCopyTxcd; private final MappedByteBuffer type0; private final MappedByteBuffer type1; private final MappedByteBuffer type2; @@ -133,6 +134,7 @@ static List headers(int length) { new ColumnHeader("txnData.STATUS_CODE", 1, length), new ColumnHeader("txnData.TO_HI", 32, length), new ColumnHeader("txnData.TO_LO", 32, length), + new ColumnHeader("txnData.TX_COPY_TXCD", 1, length), new ColumnHeader("txnData.TYPE0", 1, length), new ColumnHeader("txnData.TYPE1", 1, length), new ColumnHeader("txnData.TYPE2", 1, length), @@ -178,14 +180,15 @@ public Trace(List buffers) { this.statusCode = buffers.get(31); this.toHi = buffers.get(32); this.toLo = buffers.get(33); - this.type0 = buffers.get(34); - this.type1 = buffers.get(35); - this.type2 = buffers.get(36); - this.value = buffers.get(37); - this.wcpArgOneLo = buffers.get(38); - this.wcpArgTwoLo = buffers.get(39); - this.wcpInst = buffers.get(40); - this.wcpRes = buffers.get(41); + this.txCopyTxcd = buffers.get(34); + this.type0 = buffers.get(35); + this.type1 = buffers.get(36); + this.type2 = buffers.get(37); + this.value = buffers.get(38); + this.wcpArgOneLo = buffers.get(39); + this.wcpArgTwoLo = buffers.get(40); + this.wcpInst = buffers.get(41); + this.wcpRes = buffers.get(42); } public int size() { @@ -716,23 +719,35 @@ public Trace toLo(final Bytes b) { return this; } - public Trace type0(final Boolean b) { + public Trace txCopyTxcd(final Boolean b) { if (filled.get(34)) { - throw new IllegalStateException("txnData.TYPE0 already set"); + throw new IllegalStateException("txnData.TX_COPY_TXCD already set"); } else { filled.set(34); } + txCopyTxcd.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace type0(final Boolean b) { + if (filled.get(35)) { + throw new IllegalStateException("txnData.TYPE0 already set"); + } else { + filled.set(35); + } + type0.put((byte) (b ? 1 : 0)); return this; } public Trace type1(final Boolean b) { - if (filled.get(35)) { + if (filled.get(36)) { throw new IllegalStateException("txnData.TYPE1 already set"); } else { - filled.set(35); + filled.set(36); } type1.put((byte) (b ? 1 : 0)); @@ -741,10 +756,10 @@ public Trace type1(final Boolean b) { } public Trace type2(final Boolean b) { - if (filled.get(36)) { + if (filled.get(37)) { throw new IllegalStateException("txnData.TYPE2 already set"); } else { - filled.set(36); + filled.set(37); } type2.put((byte) (b ? 1 : 0)); @@ -753,10 +768,10 @@ public Trace type2(final Boolean b) { } public Trace value(final Bytes b) { - if (filled.get(37)) { + if (filled.get(38)) { throw new IllegalStateException("txnData.VALUE already set"); } else { - filled.set(37); + filled.set(38); } final byte[] bs = b.toArrayUnsafe(); @@ -769,10 +784,10 @@ public Trace value(final Bytes b) { } public Trace wcpArgOneLo(final Bytes b) { - if (filled.get(38)) { + if (filled.get(39)) { throw new IllegalStateException("txnData.WCP_ARG_ONE_LO already set"); } else { - filled.set(38); + filled.set(39); } final byte[] bs = b.toArrayUnsafe(); @@ -785,10 +800,10 @@ public Trace wcpArgOneLo(final Bytes b) { } public Trace wcpArgTwoLo(final Bytes b) { - if (filled.get(39)) { + if (filled.get(40)) { throw new IllegalStateException("txnData.WCP_ARG_TWO_LO already set"); } else { - filled.set(39); + filled.set(40); } final byte[] bs = b.toArrayUnsafe(); @@ -801,10 +816,10 @@ public Trace wcpArgTwoLo(final Bytes b) { } public Trace wcpInst(final UnsignedByte b) { - if (filled.get(40)) { + if (filled.get(41)) { throw new IllegalStateException("txnData.WCP_INST already set"); } else { - filled.set(40); + filled.set(41); } wcpInst.put(b.toByte()); @@ -813,10 +828,10 @@ public Trace wcpInst(final UnsignedByte b) { } public Trace wcpRes(final Boolean b) { - if (filled.get(41)) { + if (filled.get(42)) { throw new IllegalStateException("txnData.WCP_RES already set"); } else { - filled.set(41); + filled.set(42); } wcpRes.put((byte) (b ? 1 : 0)); @@ -962,34 +977,38 @@ public Trace validateRow() { } if (!filled.get(34)) { - throw new IllegalStateException("txnData.TYPE0 has not been filled"); + throw new IllegalStateException("txnData.TX_COPY_TXCD has not been filled"); } if (!filled.get(35)) { - throw new IllegalStateException("txnData.TYPE1 has not been filled"); + throw new IllegalStateException("txnData.TYPE0 has not been filled"); } if (!filled.get(36)) { - throw new IllegalStateException("txnData.TYPE2 has not been filled"); + throw new IllegalStateException("txnData.TYPE1 has not been filled"); } if (!filled.get(37)) { - throw new IllegalStateException("txnData.VALUE has not been filled"); + throw new IllegalStateException("txnData.TYPE2 has not been filled"); } if (!filled.get(38)) { - throw new IllegalStateException("txnData.WCP_ARG_ONE_LO has not been filled"); + throw new IllegalStateException("txnData.VALUE has not been filled"); } if (!filled.get(39)) { - throw new IllegalStateException("txnData.WCP_ARG_TWO_LO has not been filled"); + throw new IllegalStateException("txnData.WCP_ARG_ONE_LO has not been filled"); } if (!filled.get(40)) { - throw new IllegalStateException("txnData.WCP_INST has not been filled"); + throw new IllegalStateException("txnData.WCP_ARG_TWO_LO has not been filled"); } if (!filled.get(41)) { + throw new IllegalStateException("txnData.WCP_INST has not been filled"); + } + + if (!filled.get(42)) { throw new IllegalStateException("txnData.WCP_RES has not been filled"); } @@ -1137,34 +1156,38 @@ public Trace fillAndValidateRow() { } if (!filled.get(34)) { - type0.position(type0.position() + 1); + txCopyTxcd.position(txCopyTxcd.position() + 1); } if (!filled.get(35)) { - type1.position(type1.position() + 1); + type0.position(type0.position() + 1); } if (!filled.get(36)) { - type2.position(type2.position() + 1); + type1.position(type1.position() + 1); } if (!filled.get(37)) { - value.position(value.position() + 32); + type2.position(type2.position() + 1); } if (!filled.get(38)) { - wcpArgOneLo.position(wcpArgOneLo.position() + 32); + value.position(value.position() + 32); } if (!filled.get(39)) { - wcpArgTwoLo.position(wcpArgTwoLo.position() + 32); + wcpArgOneLo.position(wcpArgOneLo.position() + 32); } if (!filled.get(40)) { - wcpInst.position(wcpInst.position() + 1); + wcpArgTwoLo.position(wcpArgTwoLo.position() + 32); } if (!filled.get(41)) { + wcpInst.position(wcpInst.position() + 1); + } + + if (!filled.get(42)) { wcpRes.position(wcpRes.position() + 1); } diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java index 23a51d395e..461c63e0d0 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java @@ -72,6 +72,9 @@ public final class TransactionSnapshot extends ModuleOperation { /** The payload of the transaction, calldata or initcode */ private final Bytes payload; + + private final int callDataSize; + private final long gasLimit; private final BigInteger effectiveGasPrice; private final Optional maxFeePerGas; @@ -116,6 +119,7 @@ public TransactionSnapshot( this.effectiveGasPrice = effectiveGasPrice; this.maxFeePerGas = maxFeePerGas; this.maxPriorityFeePerGas = maxPriorityFeePerGas; + this.callDataSize = this.isDeployment ? 0 : this.payload.size(); } public static TransactionSnapshot fromTransaction( diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java index 69a831c511..09043b28ad 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java @@ -54,6 +54,7 @@ public class TxnData implements Module { private static final int N_ROWS_TX_MAX = Math.max(Math.max(N_ROWS_FRONTIER_TX, N_ROWS_ACCESS_LIST_TX), N_ROWS_EIP_1559_TX); private static final int LT = 16; + private static final int ISZERO = 21; static final int COMMON_RLP_TXN_PHASE_NUMBER_0 = 0; static final int COMMON_RLP_TXN_PHASE_NUMBER_1 = 7; static final int COMMON_RLP_TXN_PHASE_NUMBER_2 = 2; @@ -131,11 +132,15 @@ public void callWcp() { final List wcpArgOneLo = setWcpArgumentOne(this.currentBlock().currentTx()); final List wcpArgTwoLo = setWcpArgumentTwo(this.currentBlock(), this.currentBlock().currentTx()); + // wcp call row from 0 to 3 for (int ct = 0; ct < 4; ct++) { this.wcp.callLT(Bytes32.leftPad(wcpArgOneLo.get(ct)), Bytes32.leftPad(wcpArgTwoLo.get(ct))); } + // wcp call row 4 + this.wcp.callISZERO(Bytes32.leftPad(wcpArgOneLo.get(4))); + // wcp call row 5 to 7 for Type 2 transaction only if (this.currentBlock().currentTx().type() == TransactionType.EIP1559) { - for (int ct = 4; ct < 7; ct++) { + for (int ct = 5; ct < 8; ct++) { this.wcp.callLT(Bytes32.leftPad(wcpArgOneLo.get(ct)), Bytes32.leftPad(wcpArgTwoLo.get(ct))); } } @@ -232,21 +237,20 @@ private List setWcpInst(TransactionSnapshot tx) { LT, // ct = 0 LT, // ct = 1 LT, // ct = 2 - LT // ct = 3 + LT, // ct = 3 + ISZERO // ct = 4 ); List suffix = switch (tx.type()) { case FRONTIER, ACCESS_LIST -> List.of( - 0, // ct = 4 0, // ct = 5 0, // ct = 6 0 // ct = 7 ); case EIP1559 -> List.of( - LT, // ct = 4 LT, // ct = 5 LT, // ct = 6 - 0 // ct = 7 + LT // ct = 7 ); default -> throw new RuntimeException("transaction type not supported"); }; @@ -260,10 +264,10 @@ private List setWcpArgumentOne(TransactionSnapshot tx) { output.add(1, Bytes16.leftPad(Bytes.ofUnsignedLong(tx.gasLimit()))); // ct = 1 output.add(2, Bytes16.leftPad(bigIntegerToBytes(tx.getLimitMinusLeftoverGas()))); // ct = 2 output.add(3, Bytes16.leftPad(Bytes.ofUnsignedLong(tx.refundCounter()))); // ct = 3 + output.add(4, Bytes16.leftPad(Bytes.ofUnsignedLong(tx.callDataSize()))); // ct = 4 switch (tx.type()) { case FRONTIER, ACCESS_LIST -> { - output.add(4, Bytes16.ZERO); // ct = 4 output.add(5, Bytes16.ZERO); // ct = 5 output.add(6, Bytes16.ZERO); // ct = 6 output.add(7, Bytes16.ZERO); // ct = 7 @@ -272,10 +276,9 @@ private List setWcpArgumentOne(TransactionSnapshot tx) { case EIP1559 -> { final Bytes16 maxFeePerGas = Bytes16.leftPad(bigIntegerToBytes(tx.maxFeePerGas().orElseThrow().getAsBigInteger())); - output.add(4, maxFeePerGas); // ct = 4 output.add(5, maxFeePerGas); // ct = 5 output.add(6, maxFeePerGas); // ct = 6 - output.add(7, Bytes16.ZERO); // ct = 7 + output.add(7, maxFeePerGas); // ct = 7 } default -> throw new RuntimeException("transaction type not supported"); } @@ -291,23 +294,23 @@ private List setWcpArgumentTwo(BlockSnapshot block, TransactionSnapshot Bytes16.leftPad(bigIntegerToBytes(tx.getMaximalUpfrontCost())), // ct = 0 Bytes16.leftPad(Bytes.ofUnsignedLong(tx.getUpfrontGasCost())), // ct = 1 limitMinusLeftOverGasDividedByTwo, // ct = 2 - limitMinusLeftOverGasDividedByTwo // ct = 3 + limitMinusLeftOverGasDividedByTwo, // ct = 3 + Bytes16.ZERO // ct = 4 ); List suffixTwos = switch (tx.type()) { case FRONTIER, ACCESS_LIST -> List.of( - Bytes16.ZERO, // ct = 4 Bytes16.ZERO, // ct = 5 Bytes16.ZERO, // ct = 6 Bytes16.ZERO // ct =7 ); case EIP1559 -> List.of( Bytes16.leftPad( - bigIntegerToBytes(block.getBaseFee().orElseThrow().getAsBigInteger())), // ct = 4 + bigIntegerToBytes(block.getBaseFee().orElseThrow().getAsBigInteger())), // ct = 5 Bytes16.leftPad( bigIntegerToBytes( - tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger())), // ct = 5 + tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger())), // ct = 6 Bytes16.leftPad( bigIntegerToBytes( block @@ -315,10 +318,7 @@ private List setWcpArgumentTwo(BlockSnapshot block, TransactionSnapshot .orElseThrow() .getAsBigInteger() .add( - tx.maxPriorityFeePerGas() - .orElseThrow() - .getAsBigInteger()))), // ct = 6 - Bytes16.ZERO // ct = 7 + tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger()))) // ct = 7 ); default -> throw new IllegalStateException("transaction type not supported:" + tx.type()); }; @@ -333,8 +333,9 @@ private List setWcpRes(BlockSnapshot block, TransactionSnapshot tx) { false, // ct = 2 tx.getLimitMinusLeftoverGasDividedByTwo().compareTo(BigInteger.valueOf(tx.refundCounter())) >= 0, // ct = 3, - false, // ct = 4 + tx.callDataSize()==0, // ct = 4 false, // ct = 5 + false, // ct = 6 tx.type() == TransactionType.EIP1559 && tx.maxFeePerGas() .orElseThrow() @@ -345,8 +346,7 @@ private List setWcpRes(BlockSnapshot block, TransactionSnapshot tx) { .orElseThrow() .getAsBigInteger() .add(tx.maxPriorityFeePerGas().orElseThrow().getAsBigInteger())) - < 0, // ct = 6, - false // ct = 7 + < 0 // ct = 7, ); } @@ -454,6 +454,7 @@ private void traceTx( final List phaseNumbers = setPhaseRlpTxnNumbers(tx); final List phaseRlpTxnRcpt = setPhaseRlpTxnRcpt(); final List outgoingRlpTxnRcpt = setOutgoingRlpTxnRcpt(tx); + final boolean copyTxCd = tx.requiresEvmExecution() && tx.callDataSize() != 0; for (int ct = 0; ct < tx.maxCounter(); ct++) { trace .absTxNumMax(Bytes.ofUnsignedInt(absTxNumMax)) @@ -477,12 +478,13 @@ private void traceTx( .basefee(block.getBaseFee().orElseThrow()) .coinbaseHi(coinbase.hi()) .coinbaseLo(coinbase.lo()) - .callDataSize(tx.isDeployment() ? Bytes.EMPTY : Bytes.ofUnsignedInt(tx.payload().size())) + .callDataSize(Bytes.ofUnsignedShort(tx.callDataSize())) .initCodeSize(tx.isDeployment() ? Bytes.ofUnsignedInt(tx.payload().size()) : Bytes.EMPTY) .type0(tx.type() == TransactionType.FRONTIER) .type1(tx.type() == TransactionType.ACCESS_LIST) .type2(tx.type() == TransactionType.EIP1559) .requiresEvmExecution(tx.requiresEvmExecution()) + .txCopyTxcd(copyTxCd) .leftoverGas(Bytes.ofUnsignedLong(tx.leftoverGas())) .refundCounter(Bytes.ofUnsignedLong(tx.refundCounter())) .refundAmount(Bytes.ofUnsignedLong(tx.effectiveGasRefund())) diff --git a/zkevm-constraints b/zkevm-constraints index 435746956a..f749adf05a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 435746956ad2ec91a50702613fb9261af8c43274 +Subproject commit f749adf05a3256a81a310f32b5760927f30c7692 From c02ba02916cdb74c15bb356436ccb158262d0fe5 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sat, 3 Feb 2024 22:30:30 +0100 Subject: [PATCH 2/5] style: spotless --- .../linea/zktracer/module/txn_data/TransactionSnapshot.java | 1 - .../net/consensys/linea/zktracer/module/txn_data/TxnData.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java index 461c63e0d0..03d84eab4f 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TransactionSnapshot.java @@ -72,7 +72,6 @@ public final class TransactionSnapshot extends ModuleOperation { /** The payload of the transaction, calldata or initcode */ private final Bytes payload; - private final int callDataSize; private final long gasLimit; diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java index 09043b28ad..94d22f2fef 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java @@ -333,7 +333,7 @@ private List setWcpRes(BlockSnapshot block, TransactionSnapshot tx) { false, // ct = 2 tx.getLimitMinusLeftoverGasDividedByTwo().compareTo(BigInteger.valueOf(tx.refundCounter())) >= 0, // ct = 3, - tx.callDataSize()==0, // ct = 4 + tx.callDataSize() == 0, // ct = 4 false, // ct = 5 false, // ct = 6 tx.type() == TransactionType.EIP1559 From e0f3f4d1e65ef8dc324be0c037f0bb64ca1f7c51 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 4 Feb 2024 14:53:25 +0100 Subject: [PATCH 3/5] style: column renaming --- .../linea/zktracer/module/txn_data/Trace.java | 292 +++++++++--------- .../zktracer/module/txn_data/TxnData.java | 2 +- zkevm-constraints | 2 +- 3 files changed, 148 insertions(+), 148 deletions(-) diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java index 76d5e27e72..2bb24f0037 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/Trace.java @@ -63,6 +63,7 @@ public class Trace { private final MappedByteBuffer codeFragmentIndex; private final MappedByteBuffer coinbaseHi; private final MappedByteBuffer coinbaseLo; + private final MappedByteBuffer copyTxcdAtInitialisation; private final MappedByteBuffer ct; private final MappedByteBuffer cumulativeConsumedGas; private final MappedByteBuffer fromHi; @@ -88,7 +89,6 @@ public class Trace { private final MappedByteBuffer statusCode; private final MappedByteBuffer toHi; private final MappedByteBuffer toLo; - private final MappedByteBuffer txCopyTxcd; private final MappedByteBuffer type0; private final MappedByteBuffer type1; private final MappedByteBuffer type2; @@ -109,6 +109,7 @@ static List headers(int length) { new ColumnHeader("txnData.CODE_FRAGMENT_INDEX", 32, length), new ColumnHeader("txnData.COINBASE_HI", 32, length), new ColumnHeader("txnData.COINBASE_LO", 32, length), + new ColumnHeader("txnData.COPY_TXCD_AT_INITIALISATION", 1, length), new ColumnHeader("txnData.CT", 1, length), new ColumnHeader("txnData.CUMULATIVE_CONSUMED_GAS", 32, length), new ColumnHeader("txnData.FROM_HI", 32, length), @@ -134,7 +135,6 @@ static List headers(int length) { new ColumnHeader("txnData.STATUS_CODE", 1, length), new ColumnHeader("txnData.TO_HI", 32, length), new ColumnHeader("txnData.TO_LO", 32, length), - new ColumnHeader("txnData.TX_COPY_TXCD", 1, length), new ColumnHeader("txnData.TYPE0", 1, length), new ColumnHeader("txnData.TYPE1", 1, length), new ColumnHeader("txnData.TYPE2", 1, length), @@ -155,32 +155,32 @@ public Trace(List buffers) { this.codeFragmentIndex = buffers.get(6); this.coinbaseHi = buffers.get(7); this.coinbaseLo = buffers.get(8); - this.ct = buffers.get(9); - this.cumulativeConsumedGas = buffers.get(10); - this.fromHi = buffers.get(11); - this.fromLo = buffers.get(12); - this.gasLimit = buffers.get(13); - this.gasPrice = buffers.get(14); - this.initCodeSize = buffers.get(15); - this.initialBalance = buffers.get(16); - this.initialGas = buffers.get(17); - this.isDep = buffers.get(18); - this.leftoverGas = buffers.get(19); - this.nonce = buffers.get(20); - this.outgoingHi = buffers.get(21); - this.outgoingLo = buffers.get(22); - this.outgoingRlpTxnrcpt = buffers.get(23); - this.phaseRlpTxn = buffers.get(24); - this.phaseRlpTxnrcpt = buffers.get(25); - this.refundAmount = buffers.get(26); - this.refundCounter = buffers.get(27); - this.relTxNum = buffers.get(28); - this.relTxNumMax = buffers.get(29); - this.requiresEvmExecution = buffers.get(30); - this.statusCode = buffers.get(31); - this.toHi = buffers.get(32); - this.toLo = buffers.get(33); - this.txCopyTxcd = buffers.get(34); + this.copyTxcdAtInitialisation = buffers.get(9); + this.ct = buffers.get(10); + this.cumulativeConsumedGas = buffers.get(11); + this.fromHi = buffers.get(12); + this.fromLo = buffers.get(13); + this.gasLimit = buffers.get(14); + this.gasPrice = buffers.get(15); + this.initCodeSize = buffers.get(16); + this.initialBalance = buffers.get(17); + this.initialGas = buffers.get(18); + this.isDep = buffers.get(19); + this.leftoverGas = buffers.get(20); + this.nonce = buffers.get(21); + this.outgoingHi = buffers.get(22); + this.outgoingLo = buffers.get(23); + this.outgoingRlpTxnrcpt = buffers.get(24); + this.phaseRlpTxn = buffers.get(25); + this.phaseRlpTxnrcpt = buffers.get(26); + this.refundAmount = buffers.get(27); + this.refundCounter = buffers.get(28); + this.relTxNum = buffers.get(29); + this.relTxNumMax = buffers.get(30); + this.requiresEvmExecution = buffers.get(31); + this.statusCode = buffers.get(32); + this.toHi = buffers.get(33); + this.toLo = buffers.get(34); this.type0 = buffers.get(35); this.type1 = buffers.get(36); this.type2 = buffers.get(37); @@ -343,23 +343,35 @@ public Trace coinbaseLo(final Bytes b) { return this; } - public Trace ct(final UnsignedByte b) { + public Trace copyTxcdAtInitialisation(final Boolean b) { if (filled.get(9)) { - throw new IllegalStateException("txnData.CT already set"); + throw new IllegalStateException("txnData.COPY_TXCD_AT_INITIALISATION already set"); } else { filled.set(9); } + copyTxcdAtInitialisation.put((byte) (b ? 1 : 0)); + + return this; + } + + public Trace ct(final UnsignedByte b) { + if (filled.get(10)) { + throw new IllegalStateException("txnData.CT already set"); + } else { + filled.set(10); + } + ct.put(b.toByte()); return this; } public Trace cumulativeConsumedGas(final Bytes b) { - if (filled.get(10)) { + if (filled.get(11)) { throw new IllegalStateException("txnData.CUMULATIVE_CONSUMED_GAS already set"); } else { - filled.set(10); + filled.set(11); } final byte[] bs = b.toArrayUnsafe(); @@ -372,10 +384,10 @@ public Trace cumulativeConsumedGas(final Bytes b) { } public Trace fromHi(final Bytes b) { - if (filled.get(11)) { + if (filled.get(12)) { throw new IllegalStateException("txnData.FROM_HI already set"); } else { - filled.set(11); + filled.set(12); } final byte[] bs = b.toArrayUnsafe(); @@ -388,10 +400,10 @@ public Trace fromHi(final Bytes b) { } public Trace fromLo(final Bytes b) { - if (filled.get(12)) { + if (filled.get(13)) { throw new IllegalStateException("txnData.FROM_LO already set"); } else { - filled.set(12); + filled.set(13); } final byte[] bs = b.toArrayUnsafe(); @@ -404,10 +416,10 @@ public Trace fromLo(final Bytes b) { } public Trace gasLimit(final Bytes b) { - if (filled.get(13)) { + if (filled.get(14)) { throw new IllegalStateException("txnData.GAS_LIMIT already set"); } else { - filled.set(13); + filled.set(14); } final byte[] bs = b.toArrayUnsafe(); @@ -420,10 +432,10 @@ public Trace gasLimit(final Bytes b) { } public Trace gasPrice(final Bytes b) { - if (filled.get(14)) { + if (filled.get(15)) { throw new IllegalStateException("txnData.GAS_PRICE already set"); } else { - filled.set(14); + filled.set(15); } final byte[] bs = b.toArrayUnsafe(); @@ -436,10 +448,10 @@ public Trace gasPrice(final Bytes b) { } public Trace initCodeSize(final Bytes b) { - if (filled.get(17)) { + if (filled.get(18)) { throw new IllegalStateException("txnData.INIT_CODE_SIZE already set"); } else { - filled.set(17); + filled.set(18); } final byte[] bs = b.toArrayUnsafe(); @@ -452,10 +464,10 @@ public Trace initCodeSize(final Bytes b) { } public Trace initialBalance(final Bytes b) { - if (filled.get(15)) { + if (filled.get(16)) { throw new IllegalStateException("txnData.INITIAL_BALANCE already set"); } else { - filled.set(15); + filled.set(16); } final byte[] bs = b.toArrayUnsafe(); @@ -468,10 +480,10 @@ public Trace initialBalance(final Bytes b) { } public Trace initialGas(final Bytes b) { - if (filled.get(16)) { + if (filled.get(17)) { throw new IllegalStateException("txnData.INITIAL_GAS already set"); } else { - filled.set(16); + filled.set(17); } final byte[] bs = b.toArrayUnsafe(); @@ -484,10 +496,10 @@ public Trace initialGas(final Bytes b) { } public Trace isDep(final Boolean b) { - if (filled.get(18)) { + if (filled.get(19)) { throw new IllegalStateException("txnData.IS_DEP already set"); } else { - filled.set(18); + filled.set(19); } isDep.put((byte) (b ? 1 : 0)); @@ -496,10 +508,10 @@ public Trace isDep(final Boolean b) { } public Trace leftoverGas(final Bytes b) { - if (filled.get(19)) { + if (filled.get(20)) { throw new IllegalStateException("txnData.LEFTOVER_GAS already set"); } else { - filled.set(19); + filled.set(20); } final byte[] bs = b.toArrayUnsafe(); @@ -512,10 +524,10 @@ public Trace leftoverGas(final Bytes b) { } public Trace nonce(final Bytes b) { - if (filled.get(20)) { + if (filled.get(21)) { throw new IllegalStateException("txnData.NONCE already set"); } else { - filled.set(20); + filled.set(21); } final byte[] bs = b.toArrayUnsafe(); @@ -528,10 +540,10 @@ public Trace nonce(final Bytes b) { } public Trace outgoingHi(final Bytes b) { - if (filled.get(21)) { + if (filled.get(22)) { throw new IllegalStateException("txnData.OUTGOING_HI already set"); } else { - filled.set(21); + filled.set(22); } final byte[] bs = b.toArrayUnsafe(); @@ -544,10 +556,10 @@ public Trace outgoingHi(final Bytes b) { } public Trace outgoingLo(final Bytes b) { - if (filled.get(22)) { + if (filled.get(23)) { throw new IllegalStateException("txnData.OUTGOING_LO already set"); } else { - filled.set(22); + filled.set(23); } final byte[] bs = b.toArrayUnsafe(); @@ -560,10 +572,10 @@ public Trace outgoingLo(final Bytes b) { } public Trace outgoingRlpTxnrcpt(final Bytes b) { - if (filled.get(23)) { + if (filled.get(24)) { throw new IllegalStateException("txnData.OUTGOING_RLP_TXNRCPT already set"); } else { - filled.set(23); + filled.set(24); } final byte[] bs = b.toArrayUnsafe(); @@ -576,10 +588,10 @@ public Trace outgoingRlpTxnrcpt(final Bytes b) { } public Trace phaseRlpTxn(final UnsignedByte b) { - if (filled.get(24)) { + if (filled.get(25)) { throw new IllegalStateException("txnData.PHASE_RLP_TXN already set"); } else { - filled.set(24); + filled.set(25); } phaseRlpTxn.put(b.toByte()); @@ -588,10 +600,10 @@ public Trace phaseRlpTxn(final UnsignedByte b) { } public Trace phaseRlpTxnrcpt(final UnsignedByte b) { - if (filled.get(25)) { + if (filled.get(26)) { throw new IllegalStateException("txnData.PHASE_RLP_TXNRCPT already set"); } else { - filled.set(25); + filled.set(26); } phaseRlpTxnrcpt.put(b.toByte()); @@ -600,10 +612,10 @@ public Trace phaseRlpTxnrcpt(final UnsignedByte b) { } public Trace refundAmount(final Bytes b) { - if (filled.get(26)) { + if (filled.get(27)) { throw new IllegalStateException("txnData.REFUND_AMOUNT already set"); } else { - filled.set(26); + filled.set(27); } final byte[] bs = b.toArrayUnsafe(); @@ -616,10 +628,10 @@ public Trace refundAmount(final Bytes b) { } public Trace refundCounter(final Bytes b) { - if (filled.get(27)) { + if (filled.get(28)) { throw new IllegalStateException("txnData.REFUND_COUNTER already set"); } else { - filled.set(27); + filled.set(28); } final byte[] bs = b.toArrayUnsafe(); @@ -632,10 +644,10 @@ public Trace refundCounter(final Bytes b) { } public Trace relTxNum(final Bytes b) { - if (filled.get(28)) { + if (filled.get(29)) { throw new IllegalStateException("txnData.REL_TX_NUM already set"); } else { - filled.set(28); + filled.set(29); } final byte[] bs = b.toArrayUnsafe(); @@ -648,10 +660,10 @@ public Trace relTxNum(final Bytes b) { } public Trace relTxNumMax(final Bytes b) { - if (filled.get(29)) { + if (filled.get(30)) { throw new IllegalStateException("txnData.REL_TX_NUM_MAX already set"); } else { - filled.set(29); + filled.set(30); } final byte[] bs = b.toArrayUnsafe(); @@ -664,10 +676,10 @@ public Trace relTxNumMax(final Bytes b) { } public Trace requiresEvmExecution(final Boolean b) { - if (filled.get(30)) { + if (filled.get(31)) { throw new IllegalStateException("txnData.REQUIRES_EVM_EXECUTION already set"); } else { - filled.set(30); + filled.set(31); } requiresEvmExecution.put((byte) (b ? 1 : 0)); @@ -676,10 +688,10 @@ public Trace requiresEvmExecution(final Boolean b) { } public Trace statusCode(final Boolean b) { - if (filled.get(31)) { + if (filled.get(32)) { throw new IllegalStateException("txnData.STATUS_CODE already set"); } else { - filled.set(31); + filled.set(32); } statusCode.put((byte) (b ? 1 : 0)); @@ -688,10 +700,10 @@ public Trace statusCode(final Boolean b) { } public Trace toHi(final Bytes b) { - if (filled.get(32)) { + if (filled.get(33)) { throw new IllegalStateException("txnData.TO_HI already set"); } else { - filled.set(32); + filled.set(33); } final byte[] bs = b.toArrayUnsafe(); @@ -704,10 +716,10 @@ public Trace toHi(final Bytes b) { } public Trace toLo(final Bytes b) { - if (filled.get(33)) { + if (filled.get(34)) { throw new IllegalStateException("txnData.TO_LO already set"); } else { - filled.set(33); + filled.set(34); } final byte[] bs = b.toArrayUnsafe(); @@ -719,18 +731,6 @@ public Trace toLo(final Bytes b) { return this; } - public Trace txCopyTxcd(final Boolean b) { - if (filled.get(34)) { - throw new IllegalStateException("txnData.TX_COPY_TXCD already set"); - } else { - filled.set(34); - } - - txCopyTxcd.put((byte) (b ? 1 : 0)); - - return this; - } - public Trace type0(final Boolean b) { if (filled.get(35)) { throw new IllegalStateException("txnData.TYPE0 already set"); @@ -877,107 +877,107 @@ public Trace validateRow() { } if (!filled.get(9)) { - throw new IllegalStateException("txnData.CT has not been filled"); + throw new IllegalStateException("txnData.COPY_TXCD_AT_INITIALISATION has not been filled"); } if (!filled.get(10)) { - throw new IllegalStateException("txnData.CUMULATIVE_CONSUMED_GAS has not been filled"); + throw new IllegalStateException("txnData.CT has not been filled"); } if (!filled.get(11)) { - throw new IllegalStateException("txnData.FROM_HI has not been filled"); + throw new IllegalStateException("txnData.CUMULATIVE_CONSUMED_GAS has not been filled"); } if (!filled.get(12)) { - throw new IllegalStateException("txnData.FROM_LO has not been filled"); + throw new IllegalStateException("txnData.FROM_HI has not been filled"); } if (!filled.get(13)) { - throw new IllegalStateException("txnData.GAS_LIMIT has not been filled"); + throw new IllegalStateException("txnData.FROM_LO has not been filled"); } if (!filled.get(14)) { + throw new IllegalStateException("txnData.GAS_LIMIT has not been filled"); + } + + if (!filled.get(15)) { throw new IllegalStateException("txnData.GAS_PRICE has not been filled"); } - if (!filled.get(17)) { + if (!filled.get(18)) { throw new IllegalStateException("txnData.INIT_CODE_SIZE has not been filled"); } - if (!filled.get(15)) { + if (!filled.get(16)) { throw new IllegalStateException("txnData.INITIAL_BALANCE has not been filled"); } - if (!filled.get(16)) { + if (!filled.get(17)) { throw new IllegalStateException("txnData.INITIAL_GAS has not been filled"); } - if (!filled.get(18)) { - throw new IllegalStateException("txnData.IS_DEP has not been filled"); - } - if (!filled.get(19)) { - throw new IllegalStateException("txnData.LEFTOVER_GAS has not been filled"); + throw new IllegalStateException("txnData.IS_DEP has not been filled"); } if (!filled.get(20)) { - throw new IllegalStateException("txnData.NONCE has not been filled"); + throw new IllegalStateException("txnData.LEFTOVER_GAS has not been filled"); } if (!filled.get(21)) { - throw new IllegalStateException("txnData.OUTGOING_HI has not been filled"); + throw new IllegalStateException("txnData.NONCE has not been filled"); } if (!filled.get(22)) { - throw new IllegalStateException("txnData.OUTGOING_LO has not been filled"); + throw new IllegalStateException("txnData.OUTGOING_HI has not been filled"); } if (!filled.get(23)) { - throw new IllegalStateException("txnData.OUTGOING_RLP_TXNRCPT has not been filled"); + throw new IllegalStateException("txnData.OUTGOING_LO has not been filled"); } if (!filled.get(24)) { - throw new IllegalStateException("txnData.PHASE_RLP_TXN has not been filled"); + throw new IllegalStateException("txnData.OUTGOING_RLP_TXNRCPT has not been filled"); } if (!filled.get(25)) { - throw new IllegalStateException("txnData.PHASE_RLP_TXNRCPT has not been filled"); + throw new IllegalStateException("txnData.PHASE_RLP_TXN has not been filled"); } if (!filled.get(26)) { - throw new IllegalStateException("txnData.REFUND_AMOUNT has not been filled"); + throw new IllegalStateException("txnData.PHASE_RLP_TXNRCPT has not been filled"); } if (!filled.get(27)) { - throw new IllegalStateException("txnData.REFUND_COUNTER has not been filled"); + throw new IllegalStateException("txnData.REFUND_AMOUNT has not been filled"); } if (!filled.get(28)) { - throw new IllegalStateException("txnData.REL_TX_NUM has not been filled"); + throw new IllegalStateException("txnData.REFUND_COUNTER has not been filled"); } if (!filled.get(29)) { - throw new IllegalStateException("txnData.REL_TX_NUM_MAX has not been filled"); + throw new IllegalStateException("txnData.REL_TX_NUM has not been filled"); } if (!filled.get(30)) { - throw new IllegalStateException("txnData.REQUIRES_EVM_EXECUTION has not been filled"); + throw new IllegalStateException("txnData.REL_TX_NUM_MAX has not been filled"); } if (!filled.get(31)) { - throw new IllegalStateException("txnData.STATUS_CODE has not been filled"); + throw new IllegalStateException("txnData.REQUIRES_EVM_EXECUTION has not been filled"); } if (!filled.get(32)) { - throw new IllegalStateException("txnData.TO_HI has not been filled"); + throw new IllegalStateException("txnData.STATUS_CODE has not been filled"); } if (!filled.get(33)) { - throw new IllegalStateException("txnData.TO_LO has not been filled"); + throw new IllegalStateException("txnData.TO_HI has not been filled"); } if (!filled.get(34)) { - throw new IllegalStateException("txnData.TX_COPY_TXCD has not been filled"); + throw new IllegalStateException("txnData.TO_LO has not been filled"); } if (!filled.get(35)) { @@ -1056,107 +1056,107 @@ public Trace fillAndValidateRow() { } if (!filled.get(9)) { - ct.position(ct.position() + 1); + copyTxcdAtInitialisation.position(copyTxcdAtInitialisation.position() + 1); } if (!filled.get(10)) { - cumulativeConsumedGas.position(cumulativeConsumedGas.position() + 32); + ct.position(ct.position() + 1); } if (!filled.get(11)) { - fromHi.position(fromHi.position() + 32); + cumulativeConsumedGas.position(cumulativeConsumedGas.position() + 32); } if (!filled.get(12)) { - fromLo.position(fromLo.position() + 32); + fromHi.position(fromHi.position() + 32); } if (!filled.get(13)) { - gasLimit.position(gasLimit.position() + 32); + fromLo.position(fromLo.position() + 32); } if (!filled.get(14)) { + gasLimit.position(gasLimit.position() + 32); + } + + if (!filled.get(15)) { gasPrice.position(gasPrice.position() + 32); } - if (!filled.get(17)) { + if (!filled.get(18)) { initCodeSize.position(initCodeSize.position() + 32); } - if (!filled.get(15)) { + if (!filled.get(16)) { initialBalance.position(initialBalance.position() + 32); } - if (!filled.get(16)) { + if (!filled.get(17)) { initialGas.position(initialGas.position() + 32); } - if (!filled.get(18)) { - isDep.position(isDep.position() + 1); - } - if (!filled.get(19)) { - leftoverGas.position(leftoverGas.position() + 32); + isDep.position(isDep.position() + 1); } if (!filled.get(20)) { - nonce.position(nonce.position() + 32); + leftoverGas.position(leftoverGas.position() + 32); } if (!filled.get(21)) { - outgoingHi.position(outgoingHi.position() + 32); + nonce.position(nonce.position() + 32); } if (!filled.get(22)) { - outgoingLo.position(outgoingLo.position() + 32); + outgoingHi.position(outgoingHi.position() + 32); } if (!filled.get(23)) { - outgoingRlpTxnrcpt.position(outgoingRlpTxnrcpt.position() + 32); + outgoingLo.position(outgoingLo.position() + 32); } if (!filled.get(24)) { - phaseRlpTxn.position(phaseRlpTxn.position() + 1); + outgoingRlpTxnrcpt.position(outgoingRlpTxnrcpt.position() + 32); } if (!filled.get(25)) { - phaseRlpTxnrcpt.position(phaseRlpTxnrcpt.position() + 1); + phaseRlpTxn.position(phaseRlpTxn.position() + 1); } if (!filled.get(26)) { - refundAmount.position(refundAmount.position() + 32); + phaseRlpTxnrcpt.position(phaseRlpTxnrcpt.position() + 1); } if (!filled.get(27)) { - refundCounter.position(refundCounter.position() + 32); + refundAmount.position(refundAmount.position() + 32); } if (!filled.get(28)) { - relTxNum.position(relTxNum.position() + 32); + refundCounter.position(refundCounter.position() + 32); } if (!filled.get(29)) { - relTxNumMax.position(relTxNumMax.position() + 32); + relTxNum.position(relTxNum.position() + 32); } if (!filled.get(30)) { - requiresEvmExecution.position(requiresEvmExecution.position() + 1); + relTxNumMax.position(relTxNumMax.position() + 32); } if (!filled.get(31)) { - statusCode.position(statusCode.position() + 1); + requiresEvmExecution.position(requiresEvmExecution.position() + 1); } if (!filled.get(32)) { - toHi.position(toHi.position() + 32); + statusCode.position(statusCode.position() + 1); } if (!filled.get(33)) { - toLo.position(toLo.position() + 32); + toHi.position(toHi.position() + 32); } if (!filled.get(34)) { - txCopyTxcd.position(txCopyTxcd.position() + 1); + toLo.position(toLo.position() + 32); } if (!filled.get(35)) { diff --git a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java index 94d22f2fef..5001c72c70 100644 --- a/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java +++ b/arithmetization/src/main/java/net/consensys/linea/zktracer/module/txn_data/TxnData.java @@ -484,7 +484,7 @@ private void traceTx( .type1(tx.type() == TransactionType.ACCESS_LIST) .type2(tx.type() == TransactionType.EIP1559) .requiresEvmExecution(tx.requiresEvmExecution()) - .txCopyTxcd(copyTxCd) + .copyTxcdAtInitialisation(copyTxCd) .leftoverGas(Bytes.ofUnsignedLong(tx.leftoverGas())) .refundCounter(Bytes.ofUnsignedLong(tx.refundCounter())) .refundAmount(Bytes.ofUnsignedLong(tx.effectiveGasRefund())) diff --git a/zkevm-constraints b/zkevm-constraints index f749adf05a..783605469a 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit f749adf05a3256a81a310f32b5760927f30c7692 +Subproject commit 783605469a09099d85244e34cf7b9c05ef99122f From 549dcab45e15ab9a7845556ee263fd3f2a3e27f0 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Sun, 4 Feb 2024 15:10:38 +0100 Subject: [PATCH 4/5] fix(constraint): ras --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index 783605469a..5b01ff7473 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 783605469a09099d85244e34cf7b9c05ef99122f +Subproject commit 5b01ff7473d7b8d6e465ed27f01c0dcb6afbb766 From 6e34872176c37a6599a5a18f028ac7d67a608800 Mon Sep 17 00:00:00 2001 From: Francois Bojarski Date: Mon, 5 Feb 2024 11:02:35 +0100 Subject: [PATCH 5/5] feat(constraint): ras --- zkevm-constraints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-constraints b/zkevm-constraints index 5b01ff7473..54be331ff8 160000 --- a/zkevm-constraints +++ b/zkevm-constraints @@ -1 +1 @@ -Subproject commit 5b01ff7473d7b8d6e465ed27f01c0dcb6afbb766 +Subproject commit 54be331ff882673df42bf928dc86415c0b6a471b